From 31cb418c23b5fc1ab337e073e4113c873252a2a7 Mon Sep 17 00:00:00 2001 From: suter Date: Thu, 6 Jun 2013 18:40:06 +0200 Subject: [PATCH] Wow, I wrote a simcall! 11 files to modify to do a simple get_size on a file ... --- include/msg/datatypes.h | 1 + include/simgrid/simix.h | 3 ++- src/include/surf/surf.h | 4 ++- src/msg/msg_io.c | 3 ++- src/simix/smx_io.c | 50 +++++++++++++++++++++++++++++++---- src/simix/smx_io_private.h | 6 +++-- src/simix/smx_smurf_private.h | 3 ++- src/simix/smx_user.c | 11 ++++++-- src/surf/storage.c | 8 ++++++ src/surf/storage_private.h | 2 +- src/surf/workstation.c | 9 +++++++ 11 files changed, 86 insertions(+), 14 deletions(-) diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index d2bef83bc3..1e456ee34a 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -102,6 +102,7 @@ typedef struct simdata_file *simdata_file_t; typedef struct msg_file { char *name; /**< @brief file name */ + size_t size; simdata_file_t simdata; /**< @brief simulator data */ void *data; /**< @brief user data */ } s_msg_file_t; diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index dfdc52551e..c968eeb0dc 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -463,9 +463,10 @@ XBT_PUBLIC(int) simcall_sem_get_capacity(smx_sem_t sem); XBT_PUBLIC(double) simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream); XBT_PUBLIC(size_t) simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream); XBT_PUBLIC(smx_file_t) simcall_file_open(const char* storage, const char* path, const char* mode); -XBT_PUBLIC(int) simcall_file_close(smx_file_t fp); +XBT_PUBLIC(int) simcall_file_close(smx_file_t fd); XBT_PUBLIC(int) simcall_file_unlink(smx_file_t fd); XBT_PUBLIC(xbt_dict_t) simcall_file_ls(const char* mount, const char* path); +XBT_PUBLIC(size_t) simcall_file_get_size(smx_file_t fd); /************************** AS router **********************************/ XBT_PUBLIC(xbt_dict_t) SIMIX_asr_get_properties(const char *name); diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 398093d785..e4e6b168ed 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -232,6 +232,7 @@ typedef struct surf_storage_model_extension_public { surf_action_t(*stat) (void *storage, surf_file_t stream); surf_action_t(*unlink) (void *storage, surf_file_t stream); surf_action_t(*ls) (void *storage, const char *path); + surf_action_t(*get_size) (void *storage, surf_file_t stream); } s_surf_model_extension_storage_t; /** \ingroup SURF_models @@ -260,12 +261,13 @@ typedef struct surf_workstation_model_extension_public { double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */ double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */ surf_action_t(*open) (void *workstation, const char* storage, const char* path, const char* mode); - surf_action_t(*close) (void *workstation, surf_file_t fp); + surf_action_t(*close) (void *workstation, surf_file_t fd); surf_action_t(*read) (void *workstation, void* ptr, size_t size, size_t nmemb, surf_file_t stream); surf_action_t(*write) (void *workstation, const void* ptr, size_t size, size_t nmemb, surf_file_t stream); surf_action_t(*stat) (void *workstation, surf_file_t stream); surf_action_t(*unlink) (void *workstation, surf_file_t stream); surf_action_t(*ls) (void *workstation, const char* mount, const char *path); + surf_action_t(*get_size) (void *workstation, surf_file_t fd); int (*link_shared) (const void *link); xbt_dict_t(*get_properties) (const void *resource); diff --git a/src/msg/msg_io.c b/src/msg/msg_io.c index c5a995c054..09188a355c 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -111,7 +111,8 @@ int MSG_file_unlink(msg_file_t fd) */ size_t MSG_file_get_size(msg_file_t fd){ - return fd->simdata->smx_file->surf_file->size; + size_t size = simcall_file_get_size(fd->simdata->smx_file); + return size; } /** \ingroup msg_file_management diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 05a0d1523b..baceaf1131 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -126,14 +126,14 @@ smx_action_t SIMIX_file_open(smx_process_t process ,const char* mount, const cha } //SIMIX FILE CLOSE -void SIMIX_pre_file_close(smx_simcall_t simcall, smx_file_t fp) +void SIMIX_pre_file_close(smx_simcall_t simcall, smx_file_t fd) { - smx_action_t action = SIMIX_file_close(simcall->issuer, fp); + smx_action_t action = SIMIX_file_close(simcall->issuer, fd); xbt_fifo_push(action->simcalls, simcall); simcall->issuer->waiting_action = action; } -smx_action_t SIMIX_file_close(smx_process_t process, smx_file_t fp) +smx_action_t SIMIX_file_close(smx_process_t process, smx_file_t fd) { smx_action_t action; smx_host_t host = process->smx_host; @@ -153,7 +153,7 @@ smx_action_t SIMIX_file_close(smx_process_t process, smx_file_t fp) #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.close(host, fp->surf_file); + action->io.surf_io = surf_workstation_model->extension.workstation.close(host, fd->surf_file); surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); @@ -230,6 +230,42 @@ smx_action_t SIMIX_file_ls(smx_process_t process, const char* mount, const char return action; } +void SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd) +{ + smx_action_t action = SIMIX_file_get_size(simcall->issuer, fd); + xbt_fifo_push(action->simcalls, simcall); + simcall->issuer->waiting_action = action; +} + +smx_action_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd) +{ + smx_action_t action; + smx_host_t host = process->smx_host; + + /* check if the host is active */ + if (surf_workstation_model->extension. + workstation.get_state(host) != SURF_RESOURCE_ON) { + THROWF(host_error, 0, "Host %s failed, you cannot call this function", + sg_host_name(host)); + } + + action = xbt_mallocator_get(simix_global->action_mallocator); + action->type = SIMIX_ACTION_IO; + action->name = NULL; +#ifdef HAVE_TRACING + action->category = NULL; +#endif + + action->io.host = host; + action->io.surf_io = surf_workstation_model->extension.workstation.get_size(host, fd->surf_file); + + surf_workstation_model->action_data_set(action->io.surf_io, action); + XBT_DEBUG("Create io action %p", action); + + return action; +} + + void SIMIX_post_io(smx_action_t action) { xbt_fifo_item_t i; @@ -248,7 +284,7 @@ void SIMIX_post_io(smx_action_t action) break; case SIMCALL_FILE_CLOSE: - xbt_free(simcall_file_close__get__fp(simcall)); + xbt_free(simcall_file_close__get__fd(simcall)); simcall_file_close__set__result(simcall, 0); break; @@ -276,6 +312,10 @@ void SIMIX_post_io(smx_action_t action) // } simcall_file_ls__set__result(simcall, (action->io.surf_io)->ls_dict); break; + case SIMCALL_FILE_GET_SIZE: + xbt_free(simcall_file_close__get__fd(simcall)); + simcall_file_close__set__result(simcall, 0); + break; default: break; diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index 92a04e3d1d..21c2d98b1d 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -16,17 +16,19 @@ void SIMIX_pre_file_write(smx_simcall_t simcall, const void *ptr, size_t size, size_t nmemb, smx_file_t strea); void SIMIX_pre_file_open(smx_simcall_t simcall, const char* mount, const char* path, const char* mode); -void SIMIX_pre_file_close(smx_simcall_t simcall, smx_file_t fp); +void SIMIX_pre_file_close(smx_simcall_t simcall, smx_file_t fd); void SIMIX_pre_file_unlink(smx_simcall_t simcall, smx_file_t fd); void SIMIX_pre_file_ls(smx_simcall_t simcall, const char* mount, const char* path); +void SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd); smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size, size_t nmemb, smx_file_t stream); smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr, size_t size, size_t nmemb, smx_file_t stream); smx_action_t SIMIX_file_open(smx_process_t process, const char* storage, const char* path, const char* mode); -smx_action_t SIMIX_file_close(smx_process_t process, smx_file_t fp); +smx_action_t SIMIX_file_close(smx_process_t process, smx_file_t fd); smx_action_t SIMIX_file_unlink(smx_process_t process, smx_file_t fd); smx_action_t SIMIX_file_ls(smx_process_t process, const char *mount, const char *path); +smx_action_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd); void SIMIX_post_io(smx_action_t action); void SIMIX_io_destroy(smx_action_t action); diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index 3a77d74830..001ac6202d 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -342,9 +342,10 @@ ACTION(SIMCALL_SEM_GET_CAPACITY, sem_get_capacity, WITH_ANSWER, TINT(result), TS ACTION(SIMCALL_FILE_READ, file_read, WITHOUT_ANSWER, TDOUBLE(result), TPTR(ptr), TSIZE(size), TSIZE(nmemb), TSPEC(stream, smx_file_t)) sep \ ACTION(SIMCALL_FILE_WRITE, file_write, WITHOUT_ANSWER, TSIZE(result), TCPTR(ptr), TSIZE(size), TSIZE(nmemb), TSPEC(stream, smx_file_t)) sep \ ACTION(SIMCALL_FILE_OPEN, file_open, WITHOUT_ANSWER, TSPEC(result, smx_file_t), TSTRING(mount), TSTRING(path), TSTRING(mode)) sep \ -ACTION(SIMCALL_FILE_CLOSE, file_close, WITHOUT_ANSWER, TINT(result), TSPEC(fp, smx_file_t)) sep \ +ACTION(SIMCALL_FILE_CLOSE, file_close, WITHOUT_ANSWER, TINT(result), TSPEC(fd, smx_file_t)) sep \ ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITHOUT_ANSWER, TINT(result), TSPEC(fd, smx_file_t)) sep \ ACTION(SIMCALL_FILE_LS, file_ls, WITHOUT_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(mount), TSTRING(path)) sep \ +ACTION(SIMCALL_FILE_GET_SIZE, file_get_size, WITHOUT_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t)) sep \ ACTION(SIMCALL_ASR_GET_PROPERTIES, asr_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(name)) sep /* SIMCALL_COMM_IS_LATENCY_BOUNDED and SIMCALL_SET_CATEGORY make things complicated diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 918687c279..5765041fd7 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -1118,9 +1118,9 @@ smx_file_t simcall_file_open(const char* mount, const char* path, const char* mo * \ingroup simix_file_management * */ -int simcall_file_close(smx_file_t fp) +int simcall_file_close(smx_file_t fd) { - return simcall_BODY_file_close(fp); + return simcall_BODY_file_close(fd); } /** @@ -1140,6 +1140,13 @@ xbt_dict_t simcall_file_ls(const char* mount, const char* path) { return simcall_BODY_file_ls(mount, path); } +/** + * \ingroup simix_file_management + * + */ +size_t simcall_file_get_size (smx_file_t fd){ + return simcall_BODY_file_get_size(fd); +} #ifdef HAVE_MC diff --git a/src/surf/storage.c b/src/surf/storage.c index 33ca466700..c503a22fe5 100644 --- a/src/surf/storage.c +++ b/src/surf/storage.c @@ -81,6 +81,12 @@ static surf_action_t storage_action_ls(void *storage, const char* path) return action; } +static surf_action_t storage_action_get_size(void *storage, surf_file_t stream) +{ + surf_action_t action = storage_action_execute(storage,0,GET_SIZE); + return action; +} + static surf_action_t storage_action_unlink(void *storage, surf_file_t stream) { surf_action_t action = storage_action_execute(storage,0, UNLINK); @@ -189,6 +195,7 @@ static surf_action_t storage_action_execute (void *storage, double size, e_surf_ case STAT: case UNLINK: case LS: + case GET_SIZE: break; case READ: lmm_expand(storage_maxmin_system, STORAGE->constraint_read, @@ -494,6 +501,7 @@ static void surf_storage_model_init_internal(void) surf_storage_model->extension.storage.write = storage_action_write; surf_storage_model->extension.storage.unlink = storage_action_unlink; surf_storage_model->extension.storage.ls = storage_action_ls; + surf_storage_model->extension.storage.get_size = storage_action_get_size; if (!storage_maxmin_system) { storage_maxmin_system = lmm_system_new(storage_selective_update); diff --git a/src/surf/storage_private.h b/src/surf/storage_private.h index 1fc86215bb..a5c75fbf55 100644 --- a/src/surf/storage_private.h +++ b/src/surf/storage_private.h @@ -39,7 +39,7 @@ typedef struct storage { } s_storage_t, *storage_t; typedef enum { - READ=0, WRITE, STAT, OPEN, CLOSE, UNLINK, LS + READ=0, WRITE, STAT, OPEN, CLOSE, UNLINK, LS, GET_SIZE } e_surf_action_storage_type_t; typedef struct surf_action_storage { diff --git a/src/surf/workstation.c b/src/surf/workstation.c index 9399b42ad1..4d45d1c1e8 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -382,6 +382,14 @@ static surf_action_t ws_action_ls(void *workstation, const char* mount, const ch return model->extension.storage.ls(st, path); } +static surf_action_t ws_action_get_size(void *workstation, surf_file_t stream) +{ + storage_t st = find_storage_on_mount_list(workstation, stream->storage); + XBT_DEBUG("GET SIZE on disk '%s'",st->generic_resource.name); + surf_model_t model = st->generic_resource.model; + return model->extension.storage.get_size(st, stream); +} + static void surf_workstation_model_init_internal(void) { surf_workstation_model = surf_model_init(); @@ -441,6 +449,7 @@ static void surf_workstation_model_init_internal(void) surf_workstation_model->extension.workstation.stat = ws_action_stat; surf_workstation_model->extension.workstation.unlink = ws_action_unlink; surf_workstation_model->extension.workstation.ls = ws_action_ls; + surf_workstation_model->extension.workstation.get_size = ws_action_get_size; } void surf_workstation_model_init_current_default(void) -- 2.20.1