From af0b5e9494ca8988c8dd7d3874c3c7a400a63172 Mon Sep 17 00:00:00 2001 From: navarro Date: Thu, 29 Mar 2012 17:17:12 +0200 Subject: [PATCH] Make smx_file_t, surf_file_t and msg_file_t --- examples/msg/io/file.c | 2 +- include/msg/datatypes.h | 15 +++++++++++++++ include/msg/msg.h | 8 ++++---- include/simix/datatypes.h | 2 ++ include/simix/simix.h | 8 ++++---- include/xbt/misc.h | 11 ----------- src/include/surf/surf.h | 20 +++++++++++++------- src/msg/msg_io.c | 22 +++++++++++----------- src/simix/smx_io.c | 12 ++++++------ src/simix/smx_io_private.h | 13 ++++++++++--- src/simix/smx_smurf_private.h | 8 ++++---- src/simix/smx_user.c | 8 ++++---- src/surf/storage.c | 16 ++++++++-------- src/surf/workstation.c | 6 +++--- 14 files changed, 85 insertions(+), 66 deletions(-) diff --git a/examples/msg/io/file.c b/examples/msg/io/file.c index d0bbc68d6f..d63d941c89 100644 --- a/examples/msg/io/file.c +++ b/examples/msg/io/file.c @@ -32,7 +32,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(io_file, int host(int argc, char *argv[]) { - m_file_t file; + msg_file_t file; char* mount = bprintf("C:"); size_t read,write; if(!strcmp(MSG_process_get_name(MSG_process_self()),"0")) diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index 5b171c1273..8816397c02 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -66,6 +66,21 @@ typedef struct m_task { @{ */ typedef struct m_task *m_task_t; +/* ******************************** File ************************************ */ + +typedef struct simdata_file *simdata_file_t; + +/** @brief File datatype + @ingroup m_datatypes_management_details */ +typedef struct msg_file { + char *name; /**< @brief file name */ + simdata_file_t simdata; /**< @brief simulator data */ + void *data; /**< @brief user data */ +} s_msg_file_t; +/** @brief File datatype + @ingroup m_datatypes_management_details */ +typedef struct msg_file *msg_file_t; + /*************** Begin GPU ***************/ typedef struct simdata_gpu_task *simdata_gpu_task_t; diff --git a/include/msg/msg.h b/include/msg/msg.h index 89b94fff3b..2452e27312 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -38,10 +38,10 @@ XBT_PUBLIC(unsigned long int) MSG_get_sent_msg(void); /************************** File handling ***********************************/ -XBT_PUBLIC(size_t) MSG_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, m_file_t stream); -XBT_PUBLIC(size_t) MSG_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream); -XBT_PUBLIC(m_file_t) MSG_file_open(const char* storage, const char* path, const char* mode); -XBT_PUBLIC(int) MSG_file_close(const char* storage, m_file_t fp); +XBT_PUBLIC(size_t) MSG_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, msg_file_t stream); +XBT_PUBLIC(size_t) MSG_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, msg_file_t stream); +XBT_PUBLIC(msg_file_t) MSG_file_open(const char* storage, const char* path, const char* mode); +XBT_PUBLIC(int) MSG_file_close(const char* storage, msg_file_t fp); XBT_PUBLIC(int) MSG_file_stat(const char* storage, int fd, void* buf); diff --git a/include/simix/datatypes.h b/include/simix/datatypes.h index 093cbbd3a9..340bc1d275 100644 --- a/include/simix/datatypes.h +++ b/include/simix/datatypes.h @@ -46,6 +46,8 @@ typedef enum { typedef struct s_smx_timer* smx_timer_t; +/* ******************************** File ************************************ */ +typedef struct s_smx_file *smx_file_t; /* ******************************** Synchro ************************************ */ typedef struct s_smx_mutex *smx_mutex_t; diff --git a/include/simix/simix.h b/include/simix/simix.h index 8cfbd082a6..3c5919e9ff 100644 --- a/include/simix/simix.h +++ b/include/simix/simix.h @@ -244,10 +244,10 @@ XBT_PUBLIC(void) simcall_sem_acquire_timeout(smx_sem_t sem, XBT_PUBLIC(unsigned int) simcall_sem_acquire_any(xbt_dynar_t sems); XBT_PUBLIC(int) simcall_sem_get_capacity(smx_sem_t sem); -XBT_PUBLIC(size_t) simcall_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, m_file_t stream); -XBT_PUBLIC(size_t) simcall_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream); -XBT_PUBLIC(m_file_t) simcall_file_open(const char* storage, const char* path, const char* mode); -XBT_PUBLIC(int) simcall_file_close(const char* storage, m_file_t fp); +XBT_PUBLIC(size_t) simcall_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, smx_file_t stream); +XBT_PUBLIC(size_t) simcall_file_write(const char* storage, 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(const char* storage, smx_file_t fp); XBT_PUBLIC(int) simcall_file_stat(const char* storage, int fd, void* buf); SG_END_DECL() diff --git a/include/xbt/misc.h b/include/xbt/misc.h index a77a7feeb1..7d887b02eb 100644 --- a/include/xbt/misc.h +++ b/include/xbt/misc.h @@ -218,16 +218,5 @@ XBT_PUBLIC(const char *) xbt_procname(void); #define XBT_BACKTRACE_SIZE 10 /* FIXME: better place? Do document */ -/** @brief File datatype - @ingroup m_datatypes_management_details */ -typedef struct m_file { - char *name; /**< @brief file name */ - void *content; /**< @brief user data */ -} s_m_file_t; -/** @brief File datatype - @ingroup m_datatypes_management_details */ -typedef struct m_file *m_file_t; - - SG_END_DECL() #endif /* XBT_MISC_H */ diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index d8f73c5b55..8b7e323d19 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -93,7 +93,7 @@ typedef struct surf_action { #ifdef HAVE_TRACING char *category; /**< tracing category for categorized resource utilization monitoring */ #endif - void* file; /**< m_file_t for storage model */ + void* file; /**< surf_file_t for storage model */ size_t read_write; } s_surf_action_t; @@ -216,11 +216,17 @@ typedef struct surf_network_model_extension_public { * Public functions specific to the Storage model. */ +typedef struct surf_file { + char *name; /**< @brief host name if any */ + void *simdata; + void *data; /**< @brief user data */ +}s_surf_file_t, *surf_file_t; + typedef struct surf_storage_model_extension_public { surf_action_t(*open) (void *storage, const char* path, const char* mode); - surf_action_t(*close) (void *storage, m_file_t fp); - surf_action_t(*read) (void *storage, void* ptr, size_t size, size_t nmemb, m_file_t stream); - surf_action_t(*write) (void *storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream); + surf_action_t(*close) (void *storage, surf_file_t fp); + surf_action_t(*read) (void *storage, void* ptr, size_t size, size_t nmemb, surf_file_t stream); + surf_action_t(*write) (void *storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream); surf_action_t(*stat) (void *storage, int fd, void* buf); void* (*create_resource) (const char* id, const char* model,const char* type_id); } s_surf_model_extension_storage_t; @@ -251,9 +257,9 @@ 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, const char* storage, m_file_t fp); - surf_action_t(*read) (void *workstation, const char* storage, void* ptr, size_t size, size_t nmemb, m_file_t stream); - surf_action_t(*write) (void *workstation, const char* storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream); + surf_action_t(*close) (void *workstation, const char* storage, surf_file_t fp); + surf_action_t(*read) (void *workstation, const char* storage, void* ptr, size_t size, size_t nmemb, surf_file_t stream); + surf_action_t(*write) (void *workstation, const char* storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream); surf_action_t(*stat) (void *workstation, const char* storage, int fd, void* buf); 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 f689fe61e7..a9809ac631 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -8,9 +8,9 @@ /** @addtogroup m_file_management * \htmlonly \endhtmlonly - * (#m_file_t) and the functions for managing it. + * (#msg_file_t) and the functions for managing it. * - * \see #m_file_t + * \see #msg_file_t */ /********************************* File **************************************/ @@ -25,9 +25,9 @@ * \param stream to read * \return the number of items successfully read */ -size_t MSG_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, m_file_t stream) +size_t MSG_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, msg_file_t stream) { - return simcall_file_read(storage, ptr, size, nmemb, (m_file_t)stream); + return simcall_file_read(storage, ptr, size, nmemb, (smx_file_t)stream); } /** \ingroup m_file_management @@ -40,9 +40,9 @@ size_t MSG_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, * \param stream to write * \return the number of items successfully write */ -size_t MSG_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream) +size_t MSG_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, msg_file_t stream) { - return simcall_file_write(storage, ptr, size, nmemb, (m_file_t)stream); + return simcall_file_write(storage, ptr, size, nmemb, (smx_file_t)stream); } /** \ingroup m_file_management @@ -60,11 +60,11 @@ size_t MSG_file_write(const char* storage, const void* ptr, size_t size, size_t * a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading * is at the beginning of the file, but output is always appended to the end of the file. * - * \return An #m_file_t associated to the file + * \return An #msg_file_t associated to the file */ -m_file_t MSG_file_open(const char* storage, const char* path, const char* mode) +msg_file_t MSG_file_open(const char* storage, const char* path, const char* mode) { - return (m_file_t) simcall_file_open(storage, path, mode); + return (msg_file_t) simcall_file_open(storage, path, mode); } /** \ingroup m_file_management @@ -74,9 +74,9 @@ m_file_t MSG_file_open(const char* storage, const char* path, const char* mode) * \param fp is the file to close * \return 0 on success or 1 on error */ -int MSG_file_close(const char* storage, m_file_t fp) +int MSG_file_close(const char* storage, msg_file_t fp) { - return simcall_file_close(storage, (m_file_t)fp); + return simcall_file_close(storage, (smx_file_t)fp); } /** \ingroup m_file_management diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 209d8254cf..53c76d987c 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -28,7 +28,7 @@ void SIMIX_pre_file_read(smx_simcall_t simcall) simcall->file_read.result = (action->io.surf_io)->read_write; } -smx_action_t SIMIX_file_read(smx_process_t process, const char* storage, void* ptr, size_t size, size_t nmemb, m_file_t stream) +smx_action_t SIMIX_file_read(smx_process_t process, const char* storage, void* ptr, size_t size, size_t nmemb, smx_file_t stream) { smx_action_t action; smx_host_t host = process->smx_host; @@ -48,7 +48,7 @@ smx_action_t SIMIX_file_read(smx_process_t process, const char* storage, void* p #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.read(host->host, storage, ptr, size, nmemb, stream), + action->io.surf_io = surf_workstation_model->extension.workstation.read(host->host, storage, ptr, size, nmemb, (surf_file_t)stream), surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); @@ -70,7 +70,7 @@ void SIMIX_pre_file_write(smx_simcall_t simcall) simcall->file_write.result = (action->io.surf_io)->read_write; } -smx_action_t SIMIX_file_write(smx_process_t process, const char* storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream) +smx_action_t SIMIX_file_write(smx_process_t process, const char* storage, const void* ptr, size_t size, size_t nmemb, smx_file_t stream) { smx_action_t action; smx_host_t host = process->smx_host; @@ -90,7 +90,7 @@ smx_action_t SIMIX_file_write(smx_process_t process, const char* storage, const #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.write(host->host, storage, ptr, size, nmemb, stream); + action->io.surf_io = surf_workstation_model->extension.workstation.write(host->host, storage, ptr, size, nmemb, (surf_file_t)stream); surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); @@ -149,7 +149,7 @@ void SIMIX_pre_file_close(smx_simcall_t simcall) simcall->file_close.result = 0; } -smx_action_t SIMIX_file_close(smx_process_t process ,const char* storage, m_file_t fp) +smx_action_t SIMIX_file_close(smx_process_t process ,const char* storage, smx_file_t fp) { smx_action_t action; smx_host_t host = process->smx_host; @@ -169,7 +169,7 @@ smx_action_t SIMIX_file_close(smx_process_t process ,const char* storage, m_file #endif action->io.host = host; - action->io.surf_io = surf_workstation_model->extension.workstation.close(host->host, storage, fp); + action->io.surf_io = surf_workstation_model->extension.workstation.close(host->host, storage, (surf_file_t)fp); surf_workstation_model->action_data_set(action->io.surf_io, action); XBT_DEBUG("Create io action %p", action); diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index 861f6eaff4..83cd90257d 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -10,16 +10,23 @@ #include "simix/datatypes.h" #include "smx_smurf_private.h" +/** @brief File datatype */ +typedef struct s_smx_file { + char *name; /**< @brief host name if any */ + void *simdata; + void *data; /**< @brief user data */ +} s_smx_file_t; + void SIMIX_pre_file_read(smx_simcall_t simcall); void SIMIX_pre_file_write(smx_simcall_t simcall); void SIMIX_pre_file_open(smx_simcall_t simcall); void SIMIX_pre_file_close(smx_simcall_t simcall); void SIMIX_pre_file_stat(smx_simcall_t simcall); -smx_action_t SIMIX_file_read(smx_process_t process, const char* storage, void* ptr, size_t size, size_t nmemb, m_file_t stream); -smx_action_t SIMIX_file_write(smx_process_t process, const char* storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream); +smx_action_t SIMIX_file_read(smx_process_t process, const char* storage, void* ptr, size_t size, size_t nmemb, smx_file_t stream); +smx_action_t SIMIX_file_write(smx_process_t process, const char* storage, 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, const char* storage, m_file_t fp); +smx_action_t SIMIX_file_close(smx_process_t process, const char* storage, smx_file_t fp); smx_action_t SIMIX_file_stat(smx_process_t process, const char* storage, int fd, void* buf); void SIMIX_post_io(smx_action_t action); diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index d828e5baff..07385e95dd 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -512,7 +512,7 @@ typedef struct s_smx_simcall { void *ptr; size_t size; size_t nmemb; - m_file_t stream; + smx_file_t stream; size_t result; } file_read; @@ -521,7 +521,7 @@ typedef struct s_smx_simcall { const void *ptr; size_t size; size_t nmemb; - m_file_t stream; + smx_file_t stream; size_t result; } file_write; @@ -529,12 +529,12 @@ typedef struct s_smx_simcall { const char* storage; const char* path; const char* mode; - m_file_t result; + smx_file_t result; } file_open; struct { const char* storage; - m_file_t fp; + smx_file_t fp; int result; } file_close; diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index c0957ba1e1..9d90214e1d 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -1177,7 +1177,7 @@ int simcall_sem_get_capacity(smx_sem_t sem) return simcall->sem_get_capacity.result; } -size_t simcall_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, m_file_t stream) +size_t simcall_file_read(const char* storage, void* ptr, size_t size, size_t nmemb, smx_file_t stream) { smx_simcall_t simcall = SIMIX_simcall_mine(); @@ -1192,7 +1192,7 @@ size_t simcall_file_read(const char* storage, void* ptr, size_t size, size_t nme return simcall->file_read.result; } -size_t simcall_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream) +size_t simcall_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, smx_file_t stream) { smx_simcall_t simcall = SIMIX_simcall_mine(); @@ -1207,7 +1207,7 @@ size_t simcall_file_write(const char* storage, const void* ptr, size_t size, siz return simcall->file_write.result; } -m_file_t simcall_file_open(const char* storage, const char* path, const char* mode) +smx_file_t simcall_file_open(const char* storage, const char* path, const char* mode) { smx_simcall_t simcall = SIMIX_simcall_mine(); @@ -1220,7 +1220,7 @@ m_file_t simcall_file_open(const char* storage, const char* path, const char* mo return simcall->file_open.result; } -int simcall_file_close(const char* storage, m_file_t fp) +int simcall_file_close(const char* storage, smx_file_t fp) { smx_simcall_t simcall = SIMIX_simcall_mine(); diff --git a/src/surf/storage.c b/src/surf/storage.c index e9261519cd..e59d0c76b3 100644 --- a/src/surf/storage.c +++ b/src/surf/storage.c @@ -50,30 +50,30 @@ static surf_action_t storage_action_open(void *storage, const char* path, const xbt_dict_t content_dict = storage_type->content; content_t content = xbt_dict_get(content_dict,path); - m_file_t file = xbt_new0(s_m_file_t,1); + surf_file_t file = xbt_new0(s_surf_file_t,1); file->name = xbt_strdup(path); - file->content = content; + file->simdata = content; surf_action_t action = storage_action_execute(storage,0, DEFAULT); action->file = (void *)file; return action; } -static surf_action_t storage_action_close(void *storage, m_file_t fp) +static surf_action_t storage_action_close(void *storage, surf_file_t fp) { char *filename = fp->name; free(fp->name); - fp->content = NULL; + fp->simdata = NULL; xbt_free(fp); surf_action_t action = storage_action_execute(storage,0, DEFAULT); XBT_DEBUG("\tClose file '%s'",filename); return action; } -static surf_action_t storage_action_read(void *storage, void* ptr, size_t size, size_t nmemb, m_file_t stream) +static surf_action_t storage_action_read(void *storage, void* ptr, size_t size, size_t nmemb, surf_file_t stream) { char *filename = stream->name; - content_t content = (content_t)(stream->content); + content_t content = (content_t)(stream->simdata); XBT_DEBUG("\tRead file '%s' size '%Zu/%Zu'",filename,size,content->size); if(size > content->size) size = content->size; @@ -82,10 +82,10 @@ static surf_action_t storage_action_read(void *storage, void* ptr, size_t size, return action; } -static surf_action_t storage_action_write(void *storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream) +static surf_action_t storage_action_write(void *storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream) { char *filename = stream->name; - content_t content = (content_t)(stream->content); + content_t content = (content_t)(stream->simdata); XBT_DEBUG("\tWrite file '%s' size '%Zu/%Zu'",filename,size,content->size); surf_action_t action = storage_action_execute(storage,size,WRITE); diff --git a/src/surf/workstation.c b/src/surf/workstation.c index 0df7149ddd..9cc7163033 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -311,7 +311,7 @@ static surf_action_t ws_action_open(void *workstation, const char* storage, cons return model->extension.storage.open(st, path, mode); } -static surf_action_t ws_action_close(void *workstation, const char* storage, m_file_t fp) +static surf_action_t ws_action_close(void *workstation, const char* storage, surf_file_t fp) { storage_t st = find_storage_on_mount_list(workstation, storage); XBT_DEBUG("CLOSE on disk '%s'",st->generic_resource.name); @@ -319,7 +319,7 @@ static surf_action_t ws_action_close(void *workstation, const char* storage, m_f return model->extension.storage.close(st, fp); } -static surf_action_t ws_action_read(void *workstation, const char* storage, void* ptr, size_t size, size_t nmemb, m_file_t stream) +static surf_action_t ws_action_read(void *workstation, const char* storage, void* ptr, size_t size, size_t nmemb, surf_file_t stream) { storage_t st = find_storage_on_mount_list(workstation, storage); XBT_DEBUG("READ on disk '%s'",st->generic_resource.name); @@ -327,7 +327,7 @@ static surf_action_t ws_action_read(void *workstation, const char* storage, void return model->extension.storage.read(st, ptr, size, nmemb, stream); } -static surf_action_t ws_action_write(void *workstation, const char* storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream) +static surf_action_t ws_action_write(void *workstation, const char* storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream) { storage_t st = find_storage_on_mount_list(workstation, storage); XBT_DEBUG("WRITE on disk '%s'",st->generic_resource.name); -- 2.20.1