From 6ccd57a953c53876aaa887293d2e580043010178 Mon Sep 17 00:00:00 2001 From: suter Date: Thu, 11 Jul 2013 11:12:42 +0200 Subject: [PATCH] Finally succeed to bring back all the needed information from SURF to MSG in one simcall. Dynars are my friends ;) --- include/msg/datatypes.h | 9 +++++++++ include/msg/msg.h | 1 + include/simgrid/simix.h | 1 + src/include/surf/surf.h | 1 + src/msg/msg_io.c | 26 +++++++++++++++++++------- src/simix/smx_io.c | 12 ++++++++++++ src/simix/smx_io_private.h | 2 ++ src/simix/smx_smurf_private.h | 1 + src/simix/smx_user.c | 9 +++++++++ src/surf/storage_private.h | 8 -------- src/surf/workstation.c | 14 ++++++++++++++ 11 files changed, 69 insertions(+), 15 deletions(-) diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index c14242066d..53a3c8ce5a 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -102,10 +102,19 @@ typedef struct msg_vm { /* ******************************** File ************************************ */ typedef struct simdata_file *simdata_file_t; +typedef struct s_file_info { + size_t size; + char* mount_point; + char* storageId; + char* storage_type; + char* content_type; +} s_file_info_t, *msg_file_info_t; + typedef struct msg_file { char *fullname; /**< @brief file full name (path+name)*/ simdata_file_t simdata; /**< @brief simulator data */ void *data; /**< @brief user data */ + msg_file_info_t info; } s_msg_file_t; /** @brief File datatype. diff --git a/include/msg/msg.h b/include/msg/msg.h index bc4cc505b5..154af259b6 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -89,6 +89,7 @@ XBT_PUBLIC(int) MSG_file_unlink(msg_file_t fd); XBT_PUBLIC(xbt_dict_t) MSG_file_ls(const char *mount, const char *path); XBT_PUBLIC(size_t) MSG_storage_get_free_size(msg_storage_t sd); +XBT_PUBLIC(void) __MSG_file_get_info(msg_file_t fd); /************************** AS Router handling ************************************/ XBT_PUBLIC(const char *) MSG_as_router_get_property_value(const char* asr, const char *name); XBT_PUBLIC(xbt_dict_t) MSG_as_router_get_properties(const char* asr); diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 5308e81f0d..1c72dbeb1e 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -480,6 +480,7 @@ 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); +XBT_PUBLIC(xbt_dynar_t) simcall_file_get_info(smx_file_t fd); XBT_PUBLIC(size_t) simcall_storage_get_free_size (smx_storage_t storage); /************************** 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 2909fa4f46..b1aab86202 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -283,6 +283,7 @@ typedef struct surf_workstation_model_extension_public { int(*unlink) (void *workstation, surf_file_t fd); surf_action_t(*ls) (void *workstation, const char* mount, const char *path); size_t (*get_size) (void *workstation, surf_file_t fd); + xbt_dynar_t (*get_info) (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 6c8817e1e2..c443d83f95 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -18,7 +18,16 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_io, msg, */ /********************************* File **************************************/ - +void __MSG_file_get_info(msg_file_t fd){ + xbt_dynar_t info = simcall_file_get_info(fd->simdata->smx_file); + fd->info->content_type = xbt_dynar_pop_as(info, char *); + fd->info->storage_type = xbt_dynar_pop_as(info, char *); + fd->info->storageId = xbt_dynar_pop_as(info, char *); + fd->info->mount_point = xbt_dynar_pop_as(info, char *); + fd->info->size = xbt_dynar_pop_as(info, size_t); + + xbt_dynar_free_container(&info); +} /** \ingroup msg_file_management * \brief Display information related to a file descriptor * @@ -26,13 +35,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_io, msg, */ void MSG_file_dump (msg_file_t fd){ - THROW_UNIMPLEMENTED; +// THROW_UNIMPLEMENTED; /* Update the cached information first */ -// fd->info = __MSG_file_get_info(fd); -// XBT_INFO("File Descriptor information:\n\t\tFull name: '%s'" -// "\n\t\tSize: %zu\n\t\tMount point: '%s'\n\t\t Storage Id: '%s'" -// "\n\t\t Content Type: '%s'", fd->fullname, fd->info->size, NULL,NULL,NULL); -// fd->info->mount_point, fd->info->storageId, fd->info->content_type); + __MSG_file_get_info(fd); + XBT_INFO("File Descriptor information:\n\t\tFull name: '%s'" + "\n\t\tSize: %zu\n\t\tMount point: '%s'\n\t\tStorage Id: '%s'" + "\n\t\tStorage Type: '%s'\n\t\tContent Type: '%s'", + fd->fullname, fd->info->size, fd->info->mount_point, fd->info->storageId, + fd->info->storage_type, fd->info->content_type); } /** \ingroup msg_file_management @@ -72,6 +82,7 @@ msg_file_t MSG_file_open(const char* mount, const char* fullname) msg_file_t file = xbt_new(s_msg_file_t,1); file->fullname = xbt_strdup(fullname); file->simdata = xbt_new0(s_simdata_file_t,1); + file->info = xbt_new0(s_file_info_t,1); file->simdata->smx_file = simcall_file_open(mount, fullname); return file; } @@ -87,6 +98,7 @@ int MSG_file_close(msg_file_t fd) int res = simcall_file_close(fd->simdata->smx_file); free(fd->fullname); xbt_free(fd->simdata); + xbt_free(fd->info); xbt_free(fd); return res; } diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 7ebb6f1f21..78be8b0d6b 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -239,6 +239,18 @@ size_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd) fd->surf_file); } +xbt_dynar_t SIMIX_pre_file_get_info(smx_simcall_t simcall, smx_file_t fd) +{ + return SIMIX_file_get_info(simcall->issuer, fd); +} + +xbt_dynar_t SIMIX_file_get_info(smx_process_t process, smx_file_t fd) +{ + smx_host_t host = process->smx_host; + return surf_workstation_model->extension.workstation.get_info(host, + fd->surf_file); +} + size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall, smx_storage_t storage) { return SIMIX_storage_get_free_size(simcall->issuer, storage); diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index 82b447181f..d52cc64e49 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -19,6 +19,7 @@ int 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); size_t SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd); +xbt_dynar_t SIMIX_pre_file_get_info(smx_simcall_t simcall, smx_file_t fd); smx_action_t SIMIX_file_read(smx_process_t process, size_t size, smx_file_t fd); @@ -31,6 +32,7 @@ int 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); size_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd); +xbt_dynar_t SIMIX_file_get_info(smx_process_t process, smx_file_t fd); size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall, smx_storage_t storage); size_t SIMIX_storage_get_free_size(smx_process_t process, smx_storage_t storage); diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index f1fc9836ca..fe5c8fa882 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -354,6 +354,7 @@ ACTION(SIMCALL_FILE_CLOSE, file_close, WITHOUT_ANSWER, TINT(result), TSPEC(fd, s ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITH_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, WITH_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t)) sep \ +ACTION(SIMCALL_FILE_GET_INFO, file_get_info, WITH_ANSWER, TSPEC(result, xbt_dynar_t), TSPEC(fd, smx_file_t)) sep \ ACTION(SIMCALL_STORAGE_GET_FREE_SIZE, storage_get_free_size, WITH_ANSWER, TSIZE(result), TSPEC(storage, smx_storage_t)) sep \ ACTION(SIMCALL_ASR_GET_PROPERTIES, asr_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(name)) sep diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 56c1f0f4e8..15b9899de3 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -1235,6 +1235,15 @@ size_t simcall_file_get_size (smx_file_t fd){ return simcall_BODY_file_get_size(fd); } +/** + * \ingroup simix_file_management + * + */ +xbt_dynar_t simcall_file_get_info(smx_file_t fd) +{ + return simcall_BODY_file_get_info(fd); +} + /** * \ingroup simix_storage_management * \brief Return the free size on a given storage element. diff --git a/src/surf/storage_private.h b/src/surf/storage_private.h index d0a7265121..8a18c5ce67 100644 --- a/src/surf/storage_private.h +++ b/src/surf/storage_private.h @@ -22,18 +22,10 @@ typedef struct s_mount { char *name; } s_mount_t, *mount_t; -typedef struct s_file_info { - size_t size; - char* mount_point; - char* storageId; - char* content_type; -} s_file_info_t, *surf_file_info_t; - typedef struct surf_file { char *name; char *mount; size_t size; - surf_file_info_t info; } s_surf_file_t; typedef struct surf_storage { diff --git a/src/surf/workstation.c b/src/surf/workstation.c index 9b4e9598f5..3f5610aaaa 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -449,6 +449,19 @@ static size_t ws_file_get_size(void *workstation, surf_file_t fd) return fd->size; } +static xbt_dynar_t ws_file_get_info(void *workstation, surf_file_t fd) +{ + storage_t st = find_storage_on_mount_list(workstation, fd->mount); + xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL); + xbt_dynar_push_as(info, void *, &(fd->size)); + xbt_dynar_push_as(info, void *, fd->mount); + xbt_dynar_push_as(info, void *, st->generic_resource.name); + xbt_dynar_push_as(info, void *, st->type_id); + xbt_dynar_push_as(info, void *, st->content_type); + + return info; +} + static size_t ws_storage_get_free_size(void *workstation, surf_storage_t storage) { return storage->size - storage->used_size; @@ -522,6 +535,7 @@ static void surf_workstation_model_init_internal(void) surf_workstation_model->extension.workstation.unlink = ws_file_unlink; surf_workstation_model->extension.workstation.ls = ws_action_ls; surf_workstation_model->extension.workstation.get_size = ws_file_get_size; + surf_workstation_model->extension.workstation.get_info = ws_file_get_info; surf_workstation_model->extension.workstation.get_free_size = ws_storage_get_free_size; surf_workstation_model->extension.workstation.get_storage_list = ws_get_storage_list; } -- 2.20.1