From 01d1fb6aad0f3085ab2027950852d44caf9cff29 Mon Sep 17 00:00:00 2001 From: Pierre Veyre Date: Tue, 10 Sep 2013 09:59:45 +0200 Subject: [PATCH] Storage API --- include/msg/msg.h | 1 - include/simgrid/simix.h | 1 + src/include/surf/surf.h | 3 +++ src/msg/msg_io.c | 51 ++++++++++++++++++++++------------- src/simix/smx_io.c | 8 ++++++ src/simix/smx_io_private.h | 3 +++ src/simix/smx_smurf_private.h | 1 + src/simix/smx_user.c | 18 ++++++++++--- src/surf/storage.c | 9 +++++++ src/surf/storage_private.h | 1 + src/surf/surf_routing.c | 3 ++- 11 files changed, 76 insertions(+), 23 deletions(-) diff --git a/include/msg/msg.h b/include/msg/msg.h index 9f1aff9c52..50104e40cd 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -97,7 +97,6 @@ XBT_PUBLIC(size_t) MSG_storage_get_used_size(const char* name); XBT_PUBLIC(msg_storage_t) MSG_storage_get_by_name(const char *name); XBT_PUBLIC(xbt_dict_t) MSG_storage_get_properties(msg_storage_t storage); XBT_PUBLIC(xbt_dynar_t) MSG_storages_as_dynar(void); - /************************** 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 a13c31cb61..9692cbddb5 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -491,6 +491,7 @@ XBT_PUBLIC(xbt_dynar_t) simcall_file_get_info(smx_file_t fd); /***************************** Storage **********************************/ XBT_PUBLIC(size_t) simcall_storage_get_free_size (const char* name); XBT_PUBLIC(size_t) simcall_storage_get_used_size (const char* name); +XBT_PUBLIC(xbt_dict_t) simcall_storage_get_properties(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 ec366eabd3..5b63ef5a30 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -237,6 +237,7 @@ typedef struct surf_storage_model_extension_public { surf_action_t(*write) (void *storage, size_t size, surf_file_t fd); 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 *resource); } s_surf_model_extension_storage_t; /** \ingroup SURF_models @@ -584,6 +585,8 @@ XBT_PUBLIC(void) surf_storage_model_init_default(void); */ XBT_PUBLIC_DATA(s_surf_model_description_t) surf_storage_model_description[]; +XBT_PUBLIC_DATA(surf_model_t) surf_storage_model; + /** \ingroup SURF_models * \brief The workstation model * diff --git a/src/msg/msg_io.c b/src/msg/msg_io.c index af33f20018..1c1fdd65c8 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -113,7 +113,6 @@ msg_file_t MSG_file_open(const char* mount, const char* fullname, void* data) file->info = xbt_new0(s_file_info_t,1); file->simdata->smx_file = simcall_file_open(mount, fullname); SIMIX_file_set_data(file->simdata->smx_file, data); - return file; } @@ -181,8 +180,14 @@ xbt_dict_t MSG_file_ls(const char *mount, const char *path) /********************************* Storage **************************************/ +/** @addtogroup msg_storage_management + * \htmlonly \endhtmlonly + * (#msg_storage_t) and the functions for managing it. + * + */ + /** \ingroup msg_storage_management - * \brief Return the free space size of a storage element + * \brief Returns the free space size of a storage element * \param the storage name (#char*) * \return the free space size of the storage element (as a size_t) */ @@ -191,7 +196,7 @@ size_t MSG_storage_get_free_size(const char* name){ } /** \ingroup msg_storage_management - * \brief Return the used space size of a storage element + * \brief Returns the used space size of a storage element * \param the storage name (#char*) * \return the used space size of the storage element (as a size_t) */ @@ -207,10 +212,7 @@ size_t MSG_storage_get_used_size(const char* name){ xbt_dict_t MSG_storage_get_properties(msg_storage_t storage) { xbt_assert((storage != NULL), "Invalid parameters (storage is NULL)"); - - xbt_die( "Not implemented yet"); - return xbt_dict_new(); - //return (simcall_host_get_properties(storage)); + return (simcall_storage_get_properties(storage->simdata->smx_storage)); } /** \ingroup msg_storage_management @@ -220,22 +222,35 @@ xbt_dict_t MSG_storage_get_properties(msg_storage_t storage) */ msg_storage_t MSG_storage_get_by_name(const char *name) { - return (msg_storage_t) xbt_lib_get_elm_or_null(host_lib,name); + return (msg_storage_t) xbt_lib_get_elm_or_null(storage_lib,name); } /** \ingroup msg_storage_management - * \brief Return a dynar containing all the storages declared at a given point of time + * \brief Returns a dynar containing all the storage elements declared at a given point of time + * + * + * + * @TODO implement a new msg_storage_t structure that hides members (use xbt_dict) */ xbt_dynar_t MSG_storages_as_dynar(void) { - xbt_dynar_t storages = xbt_dynar_new(sizeof(msg_host_t), NULL); - xbt_dynar_t hosts; - msg_host_t host; - unsigned int i; - - hosts = MSG_hosts_as_dynar(); - xbt_dynar_foreach(hosts, i, host){ - xbt_dynar_push(storages,xbt_lib_get_level((void *)host, SURF_STORAGE_LEVEL)); + xbt_lib_cursor_t cursor; + char *key; + void **data; + xbt_dynar_t res = xbt_dynar_new(sizeof(msg_storage_t),NULL); + msg_storage_t storage; + xbt_lib_foreach(storage_lib, cursor, key, data) { + if(routing_get_network_element_type(key) == ROUTING_STORAGE_LEVEL) { + xbt_dictelm_t elm = xbt_dict_cursor_get_elm(cursor); + storage = xbt_new(s_msg_storage_t, 1); + storage->name = elm->key; + storage->simdata = xbt_new0(s_simdata_storage_t,1); + smx_storage_t simix_storage = xbt_lib_get_or_null(storage_lib, elm->key, SURF_STORAGE_LEVEL); + storage->simdata->smx_storage = simix_storage; + storage->data = NULL; + xbt_dynar_push(res, &storage); + } } - return storages; + + return res; } diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index e572e3a5bb..3561716337 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -293,6 +293,14 @@ size_t SIMIX_storage_get_used_size(smx_process_t process, const char* name) return surf_workstation_model->extension.workstation.get_used_size(host,name); } +xbt_dict_t SIMIX_pre_storage_get_properties(smx_simcall_t simcall, smx_storage_t storage){ + return SIMIX_storage_get_properties(storage); +} +xbt_dict_t SIMIX_storage_get_properties(smx_storage_t storage){ + xbt_assert((storage != NULL), "Invalid parameters (simix storage is NULL)"); + return surf_storage_model->extension.storage.get_properties(storage); +} + void SIMIX_post_io(smx_action_t action) { xbt_fifo_item_t i; diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index 76396fa695..584adc48f3 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -44,6 +44,9 @@ size_t SIMIX_storage_get_free_size(smx_process_t process,const char* name); size_t SIMIX_pre_storage_get_used_size(smx_simcall_t simcall,const char* name); size_t SIMIX_storage_get_used_size(smx_process_t process,const char* name); +xbt_dict_t SIMIX_storage_get_properties(smx_storage_t storage); +xbt_dict_t SIMIX_pre_storage_get_properties(smx_simcall_t, smx_storage_t); + 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/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index 9669242dba..2176f1ff7c 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -359,6 +359,7 @@ ACTION(SIMCALL_FILE_GET_SIZE, file_get_size, WITH_ANSWER, TSIZE(result), TSPEC(f 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), TSTRING(name)) sep \ ACTION(SIMCALL_STORAGE_GET_USED_SIZE, storage_get_used_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \ +ACTION(SIMCALL_STORAGE_GET_PROPERTIES, storage_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(storage, smx_storage_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 0c02e5e001..fb1e54f398 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -1270,7 +1270,7 @@ xbt_dynar_t simcall_file_get_info(smx_file_t fd) /** * \ingroup simix_storage_management - * \brief Return the free space size on a given storage element. + * \brief Returns the free space size on a given storage element. * \param storage name * \return Return the free space size on a given storage element (as size_t) */ @@ -1280,7 +1280,7 @@ size_t simcall_storage_get_free_size (const char* name){ /** * \ingroup simix_storage_management - * \brief Return the used space size on a given storage element. + * \brief Returns the used space size on a given storage element. * \param storage name * \return Return the used space size on a given storage element (as size_t) */ @@ -1290,7 +1290,7 @@ size_t simcall_storage_get_used_size (const char* name){ /** * \ingroup simix_storage_management - * \brief Return the list of storages mounted on an host. + * \brief Returns the list of storages mounted on an host. * \param host A SIMIX host * \return a dynar containing all storages mounted on the host */ @@ -1299,6 +1299,18 @@ xbt_dynar_t simcall_host_get_storage_list(smx_host_t host) return simcall_BODY_host_get_storage_list(host); } +/** + * \ingroup simix_storage_management + * \brief Returns a dict of the properties assigned to a storage element. + * + * \param storage A storage element + * \return The properties of this storage element + */ +xbt_dict_t simcall_storage_get_properties(smx_storage_t storage) +{ + return simcall_BODY_storage_get_properties(storage); +} + #ifdef HAVE_MC diff --git a/src/surf/storage.c b/src/surf/storage.c index aa0f3eb37c..8584505f7f 100644 --- a/src/surf/storage.c +++ b/src/surf/storage.c @@ -192,6 +192,11 @@ static surf_action_t storage_action_execute (void *storage, size_t size, e_surf_ return (surf_action_t) action; } +static xbt_dict_t storage_get_properties(const void *storage) +{ + return surf_resource_properties(storage); +} + static void* storage_create_resource(const char* id, const char* model, const char* type_id, const char* content_name, const char* content_type){ storage_t storage = NULL; @@ -208,6 +213,7 @@ static void* storage_create_resource(const char* id, const char* model, storage->size = 0; storage->write_actions = xbt_dynar_new(sizeof(char *),NULL); + storage_type_t storage_type = xbt_lib_get_or_null(storage_type_lib, type_id,ROUTING_STORAGE_TYPE_LEVEL); double Bread = surf_parse_get_bandwidth(xbt_dict_get(storage_type->properties,"Bread")); @@ -498,6 +504,8 @@ static void surf_storage_model_init_internal(void) surf_storage_model->extension.storage.write = storage_action_write; surf_storage_model->extension.storage.ls = storage_action_ls; + surf_storage_model->extension.storage.get_properties = storage_get_properties; + if (!storage_maxmin_system) { storage_maxmin_system = lmm_system_new(storage_selective_update); } @@ -681,3 +689,4 @@ void storage_register_callbacks() { sg_platf_storage_type_add_cb(storage_parse_storage_type); sg_platf_mount_add_cb(storage_parse_mount); } + diff --git a/src/surf/storage_private.h b/src/surf/storage_private.h index fe8db87c6d..eed61abde2 100644 --- a/src/surf/storage_private.h +++ b/src/surf/storage_private.h @@ -39,6 +39,7 @@ typedef struct surf_storage { size_t used_size; char *type_id; xbt_dynar_t write_actions; + xbt_dict_t properties; } s_storage_t, *storage_t; typedef enum { diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 7380bf694a..e10de03441 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -20,7 +20,8 @@ int ROUTING_HOST_LEVEL; //Routing level int SURF_CPU_LEVEL; //Surf cpu level int SURF_WKS_LEVEL; //Surf workstation level int SIMIX_HOST_LEVEL; //Simix level -int MSG_HOST_LEVEL; //Msg level +int SIMIX_STORAGE_LEVEL; //Simix level +int MSG_HOST_LEVEL; //Msg host level int SD_HOST_LEVEL; //Simdag level int COORD_HOST_LEVEL=0; //Coordinates level int NS3_HOST_LEVEL; //host node for ns3 -- 2.20.1