From: navarro Date: Tue, 31 Jan 2012 14:01:40 +0000 (+0100) Subject: Implement file open read and stat in simix. X-Git-Tag: exp_20120216~97^2~23 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/095b4b57dba45599d3d4b4d8ac36230b2cbeb6c0?hp=33145f3a1e718d721f062d152cda9a98d1aab5b8 Implement file open read and stat in simix. --- diff --git a/include/simix/simix.h b/include/simix/simix.h index beab8b6446..6022a19e18 100644 --- a/include/simix/simix.h +++ b/include/simix/simix.h @@ -246,6 +246,10 @@ XBT_PUBLIC(int) simcall_sem_get_capacity(smx_sem_t sem); XBT_PUBLIC(size_t) 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* path, const char* mode); +XBT_PUBLIC(size_t) simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t* stream); +XBT_PUBLIC(int) simcall_file_close(smx_file_t* fp); +XBT_PUBLIC(int) simcall_file_stat(int fd, void* buf); SG_END_DECL() #endif /* _SIMIX_SIMIX_H */ diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index e4072e62d8..57206589c4 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -47,7 +47,7 @@ smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size, size action->io.host = host; // TODO in surf model disk??? - // action->io.surf_io = surf_workstation_model->extension.disk.read(host->host, name), + // action->io.surf_io = surf_workstation_model->extension.storage.read(host->host, name), action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 1.0); surf_workstation_model->action_data_set(action->io.surf_io, action); @@ -89,7 +89,7 @@ smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr, size_t siz action->io.host = host; // TODO in surf model disk??? - // action->io.surf_io = surf_workstation_model->extension.disk.write(host->host, name), + // action->io.surf_io = surf_workstation_model->extension.storage.write(host->host, name), action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 2.0); surf_workstation_model->action_data_set(action->io.surf_io, action); @@ -98,6 +98,125 @@ smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr, size_t siz return action; } +//SIMIX FILE OPEN +void SIMIX_pre_file_open(smx_simcall_t simcall) +{ + smx_action_t action = SIMIX_file_open(simcall->issuer, + simcall->file_open.path, + simcall->file_open.mode); + xbt_fifo_push(action->simcalls, simcall); + simcall->issuer->waiting_action = action; +} + +smx_action_t SIMIX_file_open(smx_process_t process, const char* path, const char* mode) +{ + 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->host) != SURF_RESOURCE_ON) { + THROWF(host_error, 0, "Host %s failed, you cannot call this function", + host->name); + } + + 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; + // TODO in surf model disk??? + // action->io.surf_io = surf_workstation_model->extension.storage.open(host->host, name), + action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 3.0); + + surf_workstation_model->action_data_set(action->io.surf_io, action); + XBT_DEBUG("Create io action %p", action); + + return action; +} + +//SIMIX FILE CLOSE +void SIMIX_pre_file_close(smx_simcall_t simcall) +{ + smx_action_t action = SIMIX_file_close(simcall->issuer, + simcall->file_close.fp); + 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 action; + smx_host_t host = process->smx_host; + + /* check if the host is active */ + if (surf_workstation_model->extension. + workstation.get_state(host->host) != SURF_RESOURCE_ON) { + THROWF(host_error, 0, "Host %s failed, you cannot call this function", + host->name); + } + + 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; + // TODO in surf model disk??? + // action->io.surf_io = surf_workstation_model->extension.storage.close(host->host, name), + action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 4.0); + + surf_workstation_model->action_data_set(action->io.surf_io, action); + XBT_DEBUG("Create io action %p", action); + + return action; +} + +//SIMIX FILE STAT +void SIMIX_pre_file_stat(smx_simcall_t simcall) +{ + smx_action_t action = SIMIX_file_stat(simcall->issuer, + simcall->file_stat.fd, + simcall->file_stat.buf); + xbt_fifo_push(action->simcalls, simcall); + simcall->issuer->waiting_action = action; +} + +smx_action_t SIMIX_file_stat(smx_process_t process, int fd, void* buf) +{ + 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->host) != SURF_RESOURCE_ON) { + THROWF(host_error, 0, "Host %s failed, you cannot call this function", + host->name); + } + + 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; + // TODO in surf model disk??? + // action->io.surf_io = surf_workstation_model->extension.storage.stat(host->host, name), + action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 5.0); + + 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) { switch (surf_workstation_model->action_state_get(action->io.surf_io)) { diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index cca116a088..c2ffde4d3c 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -21,8 +21,15 @@ typedef struct s_smx_file *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, 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* path, const char* mode); +smx_action_t SIMIX_file_close(smx_process_t process, smx_file_t* fp); +smx_action_t SIMIX_file_stat(smx_process_t process, int fd, void* buf); void SIMIX_post_io(smx_action_t action); void SIMIX_io_destroy(smx_action_t action); diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index 06a084ed53..56863f8051 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -490,12 +490,15 @@ void SIMIX_simcall_pre(smx_simcall_t simcall, int value) break; case SIMCALL_FILE_OPEN: + SIMIX_pre_file_open(simcall); break; case SIMCALL_FILE_CLOSE: + SIMIX_pre_file_close(simcall); break; case SIMCALL_FILE_STAT: + SIMIX_pre_file_stat(simcall); break; case SIMCALL_NONE: diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index 4135e30c7c..026252c691 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -534,6 +534,13 @@ typedef struct s_smx_simcall { int result; } file_close; + struct { + int fd; + //Next should be struct stat* buf + void* buf; + int result; + } file_stat; + }; } s_smx_simcall_t, *smx_simcall_t; diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 255907e1f3..e26d97fe81 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -1205,6 +1205,41 @@ size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t return simcall->file_write.result; } +smx_file_t* simcall_file_open(const char* path, const char* mode) +{ + smx_simcall_t simcall = SIMIX_simcall_mine(); + + simcall->call = SIMCALL_FILE_OPEN; + simcall->file_open.path = path; + simcall->file_open.mode = mode; + SIMIX_simcall_push(simcall->issuer); + + return simcall->file_open.result; +} + +int simcall_file_close(smx_file_t* fp) +{ + smx_simcall_t simcall = SIMIX_simcall_mine(); + + simcall->call = SIMCALL_FILE_CLOSE; + simcall->file_close.fp = fp; + SIMIX_simcall_push(simcall->issuer); + + return simcall->file_close.result; +} + +int simcall_file_stat(int fd, void* buf) +{ + smx_simcall_t simcall = SIMIX_simcall_mine(); + + simcall->call = SIMCALL_FILE_STAT; + simcall->file_stat.fd = fd; + simcall->file_stat.buf = buf; + SIMIX_simcall_push(simcall->issuer); + + return simcall->file_stat.result; +} + /* ************************************************************************** */ /** @brief returns a printable string representing a simcall */