From 5f1b7209de9aa1fa4d24ff0ff80c6937a7a28ce7 Mon Sep 17 00:00:00 2001 From: Pierre Veyre Date: Wed, 25 Sep 2013 11:49:19 +0200 Subject: [PATCH] MSG_storage API improvements (or not) --- include/msg/msg.h | 1 + include/simgrid/platf.h | 2 -- include/simgrid/simix.h | 4 +--- src/include/surf/surf.h | 2 +- src/msg/msg_host.c | 23 ++++++++++++++++++++++- src/msg/msg_io.c | 9 +++++---- src/simix/smx_io.c | 7 +++++-- src/simix/smx_io_private.h | 2 ++ src/surf/storage.c | 7 +++---- src/surf/storage_private.h | 2 +- 10 files changed, 41 insertions(+), 18 deletions(-) diff --git a/include/msg/msg.h b/include/msg/msg.h index a748f1e722..e848f89f34 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -142,6 +142,7 @@ XBT_PUBLIC(msg_host_t) MSG_get_host_by_name(const char *name); XBT_PUBLIC(xbt_dynar_t) MSG_hosts_as_dynar(void); XBT_PUBLIC(int) MSG_get_host_number(void); XBT_PUBLIC(xbt_dynar_t) MSG_host_get_storage_list(msg_host_t host); +XBT_PUBLIC(xbt_dynar_t) MSG_host_get_storage_content(msg_host_t host); /************************** Process handling *********************************/ XBT_PUBLIC(msg_process_t) MSG_process_create(const char *name, xbt_main_func_t code, diff --git a/include/simgrid/platf.h b/include/simgrid/platf.h index 9017c61676..b9ed1ebe88 100644 --- a/include/simgrid/platf.h +++ b/include/simgrid/platf.h @@ -80,8 +80,6 @@ static inline char* sg_storage_name(sg_storage_t storage) { return storage->key; } - - /* * Platform creation functions. Instead of passing 123 arguments to the creation functions * (one for each possible XML attribute), we pass structures containing them all. It removes the diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 1c095a8822..272829ed84 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -264,8 +264,6 @@ XBT_PUBLIC(void*) SIMIX_host_self_get_data(void); XBT_PUBLIC(void*) SIMIX_host_get_data(smx_host_t host); XBT_PUBLIC(void) SIMIX_host_set_data(smx_host_t host, void *data); XBT_PUBLIC(xbt_dynar_t) SIMIX_host_get_storage_list(smx_host_t host); -XBT_PUBLIC(const char*) SIMIX_storage_get_name(smx_host_t host); - /********************************* Process ************************************/ XBT_PUBLIC(int) SIMIX_process_count(void); XBT_PUBLIC(smx_process_t) SIMIX_process_self(void); @@ -498,7 +496,7 @@ XBT_PUBLIC(xbt_dict_t) simcall_storage_get_properties(smx_storage_t storage); XBT_PUBLIC(void*) SIMIX_storage_get_data(smx_storage_t storage); XBT_PUBLIC(void) SIMIX_storage_set_data(smx_storage_t storage, void *data); XBT_PUBLIC(xbt_dict_t) SIMIX_storage_get_content(smx_storage_t storage); - +XBT_PUBLIC(const char*) SIMIX_storage_get_name(smx_host_t host); /************************** AS router **********************************/ XBT_PUBLIC(xbt_dict_t) SIMIX_asr_get_properties(const char *name); /************************** AS router simcalls ***************************/ diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 5e767d2487..49c1000180 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -238,7 +238,7 @@ typedef struct surf_storage_model_extension_public { surf_action_t(*stat) (void *storage, surf_file_t fd); surf_action_t(*ls) (void *storage, const char *path); xbt_dict_t(*get_properties) (const void *storage); - xbt_dict_t(*get_content) (void *storage); + xbt_dict_t(*get_content) (const void *storage); } s_surf_model_extension_storage_t; /** \ingroup SURF_models diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index 7b49fe7727..682b07ec07 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -341,10 +341,31 @@ double MSG_get_host_consumed_energy(msg_host_t host) { /** \ingroup m_host_management * \brief Return the list of mounted storages on an host. * \param host a host - * \return a dynar containing all mounted storages on the host + * \return a dynar containing all storages mounted on the host */ xbt_dynar_t MSG_host_get_storage_list(msg_host_t host) { xbt_assert((host != NULL), "Invalid parameters"); return (simcall_host_get_storage_list(host)); } + +/** \ingroup msg_host_management + * \brief Return the content of mounted storages on an host. + * \param host a host + * \return a dynar containing content (as a dict) of all storages mounted on the host + */ +xbt_dynar_t MSG_host_get_storage_content(msg_host_t host) +{ + xbt_assert((host != NULL), "Invalid parameters"); + xbt_dynar_t contents = xbt_dynar_new(sizeof(void *),NULL); + msg_storage_t storage; + char* storage_name; + unsigned int i; + xbt_dynar_t storage_list = simcall_host_get_storage_list(host); + xbt_dynar_foreach(storage_list, i, storage_name){ + storage = xbt_lib_get_elm_or_null(storage_lib,storage_name); +// xbt_dict_t content = SIMIX_storage_get_content(storage); +// xbt_dynar_push(contents, &content); + } + return contents; +} diff --git a/src/msg/msg_io.c b/src/msg/msg_io.c index 24147acb42..dbd31e8e6b 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -191,7 +191,7 @@ xbt_dict_t MSG_file_ls(const char *mount, const char *path) msg_storage_t __MSG_storage_create(smx_storage_t storage) { const char *name = SIMIX_storage_get_name(storage); - xbt_lib_set(storage_lib,name,MSG_HOST_LEVEL,storage); + xbt_lib_set(storage_lib,name,MSG_STORAGE_LEVEL,storage); return xbt_lib_get_elm_or_null(storage_lib, name); } @@ -210,6 +210,7 @@ void __MSG_storage_destroy(msg_storage_priv_t storage) { * This functions checks whether a storage is a valid pointer or not and return its name. */ const char *MSG_storage_get_name(msg_storage_t storage) { + xbt_assert((storage != NULL), "Invalid parameters"); return SIMIX_storage_get_name(storage); } @@ -261,7 +262,7 @@ void MSG_storage_set_property_value(msg_storage_t storage, const char *name, cha */ msg_storage_t MSG_storage_get_by_name(const char *name) { - return (msg_storage_t) xbt_lib_get_elm_or_null(storage_lib,name); + return (msg_storage_t) xbt_lib_get_or_null(storage_lib,name, MSG_STORAGE_LEVEL); } /** \ingroup msg_storage_management @@ -315,7 +316,7 @@ void *MSG_storage_get_data(msg_storage_t storage) * \brief Returns the content (file list) of a #msg_storage_t. * \param storage a storage */ -xbt_dict_t MSG_storage_get_content(msg_storage_t storage){ - +xbt_dict_t MSG_storage_get_content(msg_storage_t storage) +{ return SIMIX_storage_get_content(storage); } diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 1c16b3b73f..9d7d19eef4 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -21,7 +21,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, * \param storage the SURF storage to encapsulate * \param data some user data (may be NULL) */ -smx_host_t SIMIX_storage_create(const char *name, void *storage, void *data) +smx_storage_t SIMIX_storage_create(const char *name, void *storage, void *data) { smx_storage_priv_t smx_storage = xbt_new0(s_smx_storage_priv_t, 1); @@ -319,9 +319,12 @@ xbt_dict_t SIMIX_storage_get_properties(smx_storage_t storage){ return surf_storage_model->extension.storage.get_properties(storage); } +const char* SIMIX_pre_storage_get_name(smx_simcall_t simcall, smx_storage_t storage){ + return SIMIX_storage_get_name(storage); +} + const char* SIMIX_storage_get_name(smx_storage_t storage){ xbt_assert((storage != NULL), "Invalid parameters"); - return sg_storage_name(storage); } diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index 7914bc8d1f..8a9dcc3aa5 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -58,6 +58,8 @@ void* SIMIX_pre_storage_get_data(smx_simcall_t, smx_storage_t); xbt_dict_t SIMIX_pre_storage_get_content(smx_simcall_t simcall, smx_storage_t storage); xbt_dict_t SIMIX_storage_get_content(smx_storage_t storage); +const char* SIMIX_pre_storage_get_name(smx_simcall_t simcall, smx_storage_t storage); + void SIMIX_post_io(smx_action_t action); void SIMIX_io_destroy(smx_action_t action); void SIMIX_io_finish(smx_action_t action); diff --git a/src/surf/storage.c b/src/surf/storage.c index 21a9c630f4..7ca79b17b2 100644 --- a/src/surf/storage.c +++ b/src/surf/storage.c @@ -197,19 +197,18 @@ static xbt_dict_t storage_get_properties(const void *storage) return surf_resource_properties(surf_storage_resource_priv(storage)); } -static xbt_dict_t storage_get_content(void *storage) +static xbt_dict_t storage_get_content(const void *storage) { /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */ /* surf_action_t action = storage_action_execute(storage,0, LS); */ xbt_dict_t content_dict = xbt_dict_new(); - xbt_dict_cursor_t cursor = NULL; char *file; size_t size; - xbt_dict_foreach(((storage_t)storage)->content,cursor,file,size) + xbt_dict_foreach(((storage_t)storage)->content, cursor, file, size){ xbt_dict_set(content_dict,file,&size,NULL); - + } return content_dict; } diff --git a/src/surf/storage_private.h b/src/surf/storage_private.h index eed61abde2..e965b43514 100644 --- a/src/surf/storage_private.h +++ b/src/surf/storage_private.h @@ -33,7 +33,7 @@ typedef struct surf_storage { lmm_constraint_t constraint; /* Constraint for maximum bandwidth from connection */ lmm_constraint_t constraint_write; /* Constraint for maximum write bandwidth*/ lmm_constraint_t constraint_read; /* Constraint for maximum write bandwidth*/ - xbt_dict_t content; /* char * -> s_surf_file_t */ + xbt_dict_t content; char* content_type; size_t size; size_t used_size; -- 2.20.1