From 31c4c244b7e3690f0da5a59a117c47e9920aa420 Mon Sep 17 00:00:00 2001 From: Pierre Veyre Date: Mon, 24 Mar 2014 11:41:45 +0100 Subject: [PATCH] Removes MSG_storage_file_rename() Implements MSG_file_move() --- examples/msg/io/storage.c | 10 ++--- examples/msg/io/storage.tesh | 2 +- include/msg/msg.h | 2 +- include/simgrid/simix.h | 2 +- src/include/surf/surf.h | 23 ++++++----- src/msg/msg_io.c | 38 ++++++------------- src/simix/simcalls.in | 2 +- .../simcalls_generated_args_getter_setter.h | 16 +++----- src/simix/simcalls_generated_body.c | 11 +++--- src/simix/simcalls_generated_case.c | 4 +- src/simix/simcalls_generated_enum.h | 2 +- .../simcalls_generated_res_getter_setter.h | 8 +++- src/simix/simcalls_generated_string.c | 2 +- src/simix/smx_io.c | 9 +++-- src/simix/smx_io_private.h | 5 +-- src/simix/smx_user.c | 5 ++- src/surf/storage_interface.hpp | 8 ---- src/surf/storage_n11.cpp | 15 -------- src/surf/surf_c_bindings.cpp | 8 ++-- src/surf/workstation_interface.cpp | 31 +++++++++++++++ src/surf/workstation_interface.hpp | 11 ++++++ 21 files changed, 111 insertions(+), 103 deletions(-) diff --git a/examples/msg/io/storage.c b/examples/msg/io/storage.c index 66a1fd4d9d..afe189730a 100644 --- a/examples/msg/io/storage.c +++ b/examples/msg/io/storage.c @@ -81,15 +81,15 @@ static int host(int argc, char *argv[]){ XBT_INFO("Write %llu bytes on %s", write, file_name); MSG_file_dump(file); - MSG_file_close(file); - free(file_name); - storage_name = xbt_strdup("Disk4"); storage = MSG_storage_get_by_name(storage_name); // Now rename file from ./tmp/data.txt to ./tmp/simgrid.readme - XBT_INFO("*** Renaming '/tmp/data.txt' into '/tmp/simgrid.readme'"); - MSG_storage_file_rename(storage, "/tmp/data.txt", "/tmp/simgrid.readme"); + XBT_INFO("*** Move '/tmp/data.txt' into '/tmp/simgrid.readme'"); + MSG_file_move(file, "/home/tmp/simgrid.readme"); + + MSG_file_close(file); + free(file_name); // Now attach some user data to disk1 XBT_INFO("*** Get/set data for storage element: %s ***",storage_name); diff --git a/examples/msg/io/storage.tesh b/examples/msg/io/storage.tesh index e0e74b2754..f3512c028f 100644 --- a/examples/msg/io/storage.tesh +++ b/examples/msg/io/storage.tesh @@ -29,7 +29,7 @@ $ ${bindir:=.}/io/storage ${srcdir:=.}/examples/platforms/storage.xml "--log=roo > Storage Id: 'Disk4' > Storage Type: 'single_SSD' > Content Type: 'txt_unix' -> [ 0.007917] (1:(null)@denise) *** Renaming '/tmp/data.txt' into '/tmp/simgrid.readme' +> [ 0.007917] (1:(null)@denise) *** Move '/tmp/data.txt' into '/tmp/simgrid.readme' > [ 0.007917] (1:(null)@denise) *** Get/set data for storage element: Disk4 *** > [ 0.007917] (1:(null)@denise) Get data: '(null)' > [ 0.007917] (1:(null)@denise) Set and get data: 'Some user data' diff --git a/include/msg/msg.h b/include/msg/msg.h index cf6e52b931..f7f04a3f82 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -96,6 +96,7 @@ XBT_PUBLIC(sg_size_t) MSG_file_tell (msg_file_t fd); XBT_PUBLIC(void) __MSG_file_get_info(msg_file_t fd); XBT_PUBLIC(void) __MSG_file_priv_free(msg_file_priv_t priv); XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t storage); +XBT_PUBLIC(msg_error_t) MSG_file_move(msg_file_t fd, const char* fullpath); /************************** Storage handling ***********************************/ XBT_PUBLIC(msg_host_t) MSG_get_storage_by_name(const char *name); XBT_PUBLIC(const char *) MSG_storage_get_name(msg_storage_t storage); @@ -110,7 +111,6 @@ XBT_PUBLIC(void *) MSG_storage_get_data(msg_storage_t storage); XBT_PUBLIC(xbt_dict_t) MSG_storage_get_content(msg_storage_t storage); XBT_PUBLIC(sg_size_t) MSG_storage_get_size(msg_storage_t storage); XBT_PUBLIC(msg_error_t) MSG_storage_file_move(msg_file_t fd, msg_host_t dest, char* mount, char* fullname); -XBT_PUBLIC(msg_error_t) MSG_storage_file_rename(msg_storage_t storage, const char* src, const char* dest); XBT_PUBLIC(const char *) MSG_storage_get_host(msg_storage_t storage); /************************** AS Router handling ************************************/ XBT_PUBLIC(const char *) MSG_as_router_get_property_value(const char* asr, const char *name); diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 611453866e..fb0269864a 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -498,6 +498,7 @@ XBT_PUBLIC(sg_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(sg_size_t) simcall_file_tell(smx_file_t fd); XBT_PUBLIC(int) simcall_file_seek(smx_file_t fd, sg_size_t offset, int origin); +XBT_PUBLIC(int) simcall_file_move(smx_file_t fd, const char* fullpath); /***************************** Storage **********************************/ XBT_PUBLIC(sg_size_t) simcall_storage_get_free_size (const char* name); XBT_PUBLIC(sg_size_t) simcall_storage_get_used_size (const char* name); @@ -508,7 +509,6 @@ XBT_PUBLIC(xbt_dict_t) SIMIX_storage_get_content(smx_storage_t storage); XBT_PUBLIC(xbt_dict_t) simcall_storage_get_content(smx_storage_t storage); XBT_PUBLIC(const char*) SIMIX_storage_get_name(smx_storage_t storage); XBT_PUBLIC(sg_size_t) SIMIX_storage_get_size(smx_storage_t storage); -XBT_PUBLIC(void) simcall_storage_file_rename(smx_storage_t storage, const char* src, const char* dest); XBT_PUBLIC(const char*) SIMIX_storage_get_host(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 87fb6aac6a..c388006ee3 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -694,6 +694,19 @@ XBT_PUBLIC(size_t) surf_workstation_get_size(surf_resource_t workstation, surf_f */ XBT_PUBLIC(size_t) surf_workstation_file_tell(surf_resource_t workstation, surf_file_t fd); +/** + * @brief Move a file to another location on the *same mount point*. + * @details [long description] + * + * @param workstation The surf workstation + * @param fd The file descriptor + * @param fullpath The new full path + * @param origin Position used as a reference for the offset + * + * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED + */ +XBT_PUBLIC(int) surf_workstation_file_move(surf_resource_t workstation, surf_file_t fd, const char* fullpath); + /** * @brief Set the position indictator assiociated with the file descriptor to a new position * @details [long description] @@ -709,6 +722,7 @@ XBT_PUBLIC(size_t) surf_workstation_file_tell(surf_resource_t workstation, surf_ */ XBT_PUBLIC(int) surf_workstation_file_seek(surf_resource_t workstation, surf_file_t fd, sg_size_t offset, int origin); + /** * @brief [brief description] * @details [long description] @@ -750,15 +764,6 @@ XBT_PUBLIC(xbt_dict_t) surf_storage_get_content(surf_resource_t resource); */ XBT_PUBLIC(sg_size_t) surf_storage_get_size(surf_resource_t resource); -/** - * @brief Rename a path - * - * @param resource The surf storage - * @param src The old path - * @param dest The new path - */ -XBT_PUBLIC(void) surf_storage_rename(surf_resource_t resource, const char* src, const char* dest); - /** * @brief Get the data associated to the action * diff --git a/src/msg/msg_io.c b/src/msg/msg_io.c index c7bbe8c85c..fbaf853759 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -242,8 +242,18 @@ const char *MSG_file_get_name(msg_file_t fd) { return priv->fullpath; } +/** + * \ingroup msg_file_management + * \brief Move a file to another location on the *same mount point*. + * + */ +msg_error_t MSG_file_move (msg_file_t fd, const char* fullpath) +{ + msg_file_priv_t priv = MSG_file_priv(fd); + return simcall_file_move(priv->simdata->smx_file, fullpath); +} -/* +/** * \brief Destroys a file (internal call only) */ void __MSG_file_destroy(msg_file_priv_t file) { @@ -269,7 +279,7 @@ msg_storage_t __MSG_storage_create(smx_storage_t storage) return xbt_lib_get_elm_or_null(storage_lib, name); } -/* +/** * \brief Destroys a storage (internal call only) */ void __MSG_storage_destroy(msg_storage_priv_t storage) { @@ -402,30 +412,6 @@ sg_size_t MSG_storage_get_size(msg_storage_t storage) return SIMIX_storage_get_size(storage); } -/** - * \ingroup msg_storage_management - * - * \brief Rename the file in the contents of its associated storage. - */ -msg_error_t MSG_storage_file_rename(msg_storage_t storage, const char* src, const char* dest) -{ - simcall_storage_file_rename(storage, src, dest); - return MSG_OK; -} - -/** - * \ingroup msg_storage_management - * \brief Move a file to another location. Depending on the values of dest, dest, mount, - * and fullname, this move can be local or remote and, within a host, on the same - * mounted disk or between mounted disks. - * - */ -msg_error_t MSG_storage_file_move (msg_file_t fd, msg_host_t dest, char* mount, char* fullname) -{ - THROW_UNIMPLEMENTED; - return MSG_OK; -} - /** \ingroup msg_storage_management * * \brief Returns the host name the storage is attached to diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 59865c8b22..9c7a7dbbc1 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -118,7 +118,7 @@ file_get_size True (sg_size_t) (fd, void*, smx_file_t) file_tell True (sg_size_t) (fd, void*, smx_file_t) file_seek True (int) (fd, void*, smx_file_t) (offset, sg_size_t) (origin, int) file_get_info True (void*, xbt_dynar_t) (fd, void*, smx_file_t) -storage_file_rename True (void) (storage, void*, smx_storage_t) (src, const char*) (dest, const char*) +file_move True (int) (fd, void*, smx_file_t) (fullpath, const char*) storage_get_free_size True (sg_size_t) (name, const char*) storage_get_used_size True (sg_size_t) (name, const char*) storage_get_properties True (void*, xbt_dict_t) (storage, void*, smx_storage_t) diff --git a/src/simix/simcalls_generated_args_getter_setter.h b/src/simix/simcalls_generated_args_getter_setter.h index e76f174fd4..55ba1483c8 100644 --- a/src/simix/simcalls_generated_args_getter_setter.h +++ b/src/simix/simcalls_generated_args_getter_setter.h @@ -1142,24 +1142,18 @@ static inline smx_file_t simcall_file_get_info__get__fd(smx_simcall_t simcall){ static inline void simcall_file_get_info__set__fd(smx_simcall_t simcall, void* arg){ simcall->args[0].dp = arg; } -static inline smx_storage_t simcall_storage_file_rename__get__storage(smx_simcall_t simcall){ - return (smx_storage_t) simcall->args[0].dp; +static inline smx_file_t simcall_file_move__get__fd(smx_simcall_t simcall){ + return (smx_file_t) simcall->args[0].dp; } -static inline void simcall_storage_file_rename__set__storage(smx_simcall_t simcall, void* arg){ +static inline void simcall_file_move__set__fd(smx_simcall_t simcall, void* arg){ simcall->args[0].dp = arg; } -static inline const char* simcall_storage_file_rename__get__src(smx_simcall_t simcall){ +static inline const char* simcall_file_move__get__fullpath(smx_simcall_t simcall){ return simcall->args[1].cc; } -static inline void simcall_storage_file_rename__set__src(smx_simcall_t simcall, const char* arg){ +static inline void simcall_file_move__set__fullpath(smx_simcall_t simcall, const char* arg){ simcall->args[1].cc = arg; } -static inline const char* simcall_storage_file_rename__get__dest(smx_simcall_t simcall){ - return simcall->args[2].cc; -} -static inline void simcall_storage_file_rename__set__dest(smx_simcall_t simcall, const char* arg){ - simcall->args[2].cc = arg; -} static inline const char* simcall_storage_get_free_size__get__name(smx_simcall_t simcall){ return simcall->args[0].cc; } diff --git a/src/simix/simcalls_generated_body.c b/src/simix/simcalls_generated_body.c index c37a78b52e..5e2bf9e0d5 100644 --- a/src/simix/simcalls_generated_body.c +++ b/src/simix/simcalls_generated_body.c @@ -1765,14 +1765,13 @@ } return self->simcall.result.dp; } - inline static void simcall_BODY_storage_file_rename(smx_storage_t storage, const char* src, const char* dest) { + inline static int simcall_BODY_file_move(smx_file_t fd, const char* fullpath) { smx_process_t self = SIMIX_process_self(); - self->simcall.call = SIMCALL_STORAGE_FILE_RENAME; + self->simcall.call = SIMCALL_FILE_MOVE; memset(&self->simcall.result, 0, sizeof(self->simcall.result)); memset(self->simcall.args, 0, sizeof(self->simcall.args)); - self->simcall.args[0].dp = (void*) storage; - self->simcall.args[1].cc = (const char*) src; - self->simcall.args[2].cc = (const char*) dest; + self->simcall.args[0].dp = (void*) fd; + self->simcall.args[1].cc = (const char*) fullpath; if (self != simix_global->maestro_process) { XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); @@ -1780,7 +1779,7 @@ } else { SIMIX_simcall_pre(&self->simcall, 0); } - + return self->simcall.result.i; } inline static sg_size_t simcall_BODY_storage_get_free_size(const char* name) { smx_process_t self = SIMIX_process_self(); diff --git a/src/simix/simcalls_generated_case.c b/src/simix/simcalls_generated_case.c index cc672efe05..6d7bc913ca 100644 --- a/src/simix/simcalls_generated_case.c +++ b/src/simix/simcalls_generated_case.c @@ -546,8 +546,8 @@ case SIMCALL_FILE_GET_INFO: SIMIX_simcall_answer(simcall); break; -case SIMCALL_STORAGE_FILE_RENAME: - SIMIX_pre_storage_file_rename(simcall , (smx_storage_t) simcall->args[0].dp, simcall->args[1].cc, simcall->args[2].cc); +case SIMCALL_FILE_MOVE: + simcall->result.i = SIMIX_pre_file_move(simcall , (smx_file_t) simcall->args[0].dp, simcall->args[1].cc); SIMIX_simcall_answer(simcall); break; diff --git a/src/simix/simcalls_generated_enum.h b/src/simix/simcalls_generated_enum.h index f3a064eb33..448c05a917 100644 --- a/src/simix/simcalls_generated_enum.h +++ b/src/simix/simcalls_generated_enum.h @@ -117,7 +117,7 @@ SIMCALL_FILE_GET_SIZE, SIMCALL_FILE_TELL, SIMCALL_FILE_SEEK, SIMCALL_FILE_GET_INFO, -SIMCALL_STORAGE_FILE_RENAME, +SIMCALL_FILE_MOVE, SIMCALL_STORAGE_GET_FREE_SIZE, SIMCALL_STORAGE_GET_USED_SIZE, SIMCALL_STORAGE_GET_PROPERTIES, diff --git a/src/simix/simcalls_generated_res_getter_setter.h b/src/simix/simcalls_generated_res_getter_setter.h index bcee19440f..052b1f4456 100644 --- a/src/simix/simcalls_generated_res_getter_setter.h +++ b/src/simix/simcalls_generated_res_getter_setter.h @@ -485,8 +485,12 @@ static inline xbt_dynar_t simcall_file_get_info__get__result(smx_simcall_t simca static inline void simcall_file_get_info__set__result(smx_simcall_t simcall, void* result){ simcall->result.dp = result; } - - +static inline int simcall_file_move__get__result(smx_simcall_t simcall){ + return simcall->result.i; +} +static inline void simcall_file_move__set__result(smx_simcall_t simcall, int result){ + simcall->result.i = result; +} static inline sg_size_t simcall_storage_get_free_size__get__result(smx_simcall_t simcall){ return simcall->result.sgsz; } diff --git a/src/simix/simcalls_generated_string.c b/src/simix/simcalls_generated_string.c index ed629fa075..0f14211855 100644 --- a/src/simix/simcalls_generated_string.c +++ b/src/simix/simcalls_generated_string.c @@ -117,7 +117,7 @@ [SIMCALL_FILE_TELL] = "SIMCALL_FILE_TELL", [SIMCALL_FILE_SEEK] = "SIMCALL_FILE_SEEK", [SIMCALL_FILE_GET_INFO] = "SIMCALL_FILE_GET_INFO", -[SIMCALL_STORAGE_FILE_RENAME] = "SIMCALL_STORAGE_FILE_RENAME", +[SIMCALL_FILE_MOVE] = "SIMCALL_FILE_MOVE", [SIMCALL_STORAGE_GET_FREE_SIZE] = "SIMCALL_STORAGE_GET_FREE_SIZE", [SIMCALL_STORAGE_GET_USED_SIZE] = "SIMCALL_STORAGE_GET_USED_SIZE", [SIMCALL_STORAGE_GET_PROPERTIES] = "SIMCALL_STORAGE_GET_PROPERTIES", diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 5bfbe2060e..25c87cf078 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -290,14 +290,15 @@ int SIMIX_file_seek(smx_process_t process, smx_file_t fd, sg_size_t offset, int return surf_workstation_file_seek(host, fd->surf_file, offset, origin); } -void SIMIX_pre_storage_file_rename(smx_simcall_t simcall, smx_storage_t storage, const char* src, const char* dest) +int SIMIX_pre_file_move(smx_simcall_t simcall, smx_file_t file, const char* fullpath) { - return SIMIX_storage_file_rename(simcall->issuer, storage, src, dest); + return SIMIX_file_move(simcall->issuer, file, fullpath); } -void SIMIX_storage_file_rename(smx_process_t process, smx_storage_t storage, const char* src, const char* dest) +int SIMIX_file_move(smx_process_t process, smx_file_t file, const char* fullpath) { - return surf_storage_rename(storage, src, dest); + smx_host_t host = process->smx_host; + return surf_workstation_file_move(host, file->surf_file, fullpath); } sg_size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall, const char* name) diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index 860c9f66e3..8a3c38d7db 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -33,8 +33,7 @@ sg_size_t SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd); sg_size_t SIMIX_pre_file_tell(smx_simcall_t simcall, smx_file_t fd); xbt_dynar_t SIMIX_pre_file_get_info(smx_simcall_t simcall, smx_file_t fd); int SIMIX_pre_file_seek(smx_simcall_t simcall, smx_file_t fd, sg_size_t offset, int origin); -void SIMIX_pre_storage_file_rename(smx_simcall_t simcall,smx_storage_t storage, const char* src, const char* dest); - +int SIMIX_pre_file_move(smx_simcall_t simcall, smx_file_t fd, const char* fullpath); smx_action_t SIMIX_file_read(smx_process_t process, smx_file_t fd, sg_size_t size); smx_action_t SIMIX_file_write(smx_process_t process, smx_file_t fd, sg_size_t size); smx_action_t SIMIX_file_open(smx_process_t process, const char* fullpath); @@ -46,8 +45,8 @@ sg_size_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd); sg_size_t SIMIX_file_tell(smx_process_t process, smx_file_t fd); xbt_dynar_t SIMIX_file_get_info(smx_process_t process, smx_file_t fd); int SIMIX_file_seek(smx_process_t process, smx_file_t fd, sg_size_t offset, int origin); +int SIMIX_file_move(smx_process_t process, smx_file_t fd, const char* fullpath); -void SIMIX_storage_file_rename(smx_process_t process, smx_storage_t storage, const char* src, const char* dest); sg_size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall,const char* name); sg_size_t SIMIX_storage_get_free_size(smx_process_t process,const char* name); diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 61ffbfec21..d4ecd2f121 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -1402,11 +1402,12 @@ int simcall_file_seek(smx_file_t fd, sg_size_t offset, int origin){ /** * \ingroup simix_file_management + * \brief Move a file to another location on the *same mount point*. * */ -void simcall_storage_file_rename(smx_storage_t storage, const char* src, const char* dest) +int simcall_file_move(smx_file_t fd, const char* fullpath) { - return simcall_BODY_storage_file_rename(storage, src, dest); + return simcall_BODY_file_move(fd, fullpath); } /** diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index d70771c2f0..c63d044a69 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -219,14 +219,6 @@ public: */ virtual StorageActionPtr write(surf_file_t fd, sg_size_t size)=0; - /** - * @brief Rename a path - * - * @param src The old path - * @param dest The new path - */ - virtual void rename(const char *src, const char *dest)=0; - /** * @brief Get the content of the current Storage * diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index cfe41f84ae..5944409670 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -484,21 +484,6 @@ StorageActionPtr StorageN11::write(surf_file_t fd, sg_size_t size) return action; } -void StorageN11::rename(const char *src, const char *dest) -{ - sg_size_t *psize, *new_psize; - psize = (sg_size_t*) xbt_dict_get_or_null(p_content,src); - new_psize = xbt_new(sg_size_t, 1); - *new_psize = *psize; - if (psize){// src file exists - xbt_dict_remove(p_content, src); - xbt_dict_set(p_content, dest, new_psize,NULL); - XBT_DEBUG("Change file name from %s to %s, size '%llu'",src, dest, *psize); - } - else - XBT_DEBUG("File %s doesn't exist",src); -} - /********** * Action * **********/ diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index c4326917c9..82e93b145c 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -408,6 +408,10 @@ int surf_workstation_file_seek(surf_resource_t workstation, surf_file_t fd, sg_s return get_casted_workstation(workstation)->fileSeek(fd, offset, origin); } +int surf_workstation_file_move(surf_resource_t workstation, surf_file_t fd, const char* fullpath){ + return get_casted_workstation(workstation)->fileMove(fd, fullpath); +} + xbt_dynar_t surf_workstation_get_vms(surf_resource_t resource){ return get_casted_workstation(resource)->getVms(); } @@ -480,10 +484,6 @@ const char* surf_storage_get_host(surf_resource_t resource){ return static_cast(surf_storage_resource_priv(resource))->p_attach; } -void surf_storage_rename(surf_resource_t resource, const char* src, const char* dest){ - static_cast(surf_storage_resource_priv(resource))->rename(src, dest); -} - surf_action_t surf_cpu_execute(surf_resource_t cpu, double size){ return get_casted_cpu(cpu)->execute(size); } diff --git a/src/surf/workstation_interface.cpp b/src/surf/workstation_interface.cpp index 63c4219802..60480b9bed 100644 --- a/src/surf/workstation_interface.cpp +++ b/src/surf/workstation_interface.cpp @@ -337,6 +337,37 @@ int Workstation::fileSeek(surf_file_t fd, sg_size_t offset, int origin){ } } +int Workstation::fileMove(surf_file_t fd, const char* fullpath){ + + /* Check if the new full path is on the same mount point */ + if(!strncmp((const char*)fd->mount, fullpath, strlen(fd->mount))) + { + sg_size_t *psize, *new_psize; + psize = (sg_size_t*) xbt_dict_get_or_null(findStorageOnMountList(fd->mount)->p_content,fd->name); + new_psize = xbt_new(sg_size_t, 1); + *new_psize = *psize; + if (psize){// src file exists + xbt_dict_remove(findStorageOnMountList(fd->mount)->p_content, fd->name); + + char *path = (char *) xbt_malloc ((strlen(fullpath)-strlen(fd->mount)+1));; + strncpy(path, fullpath+strlen(fd->mount), strlen(fullpath)-strlen(fd->mount)+1); + xbt_dict_set(findStorageOnMountList(fd->mount)->p_content, path, new_psize,NULL); + XBT_DEBUG("Move file from %s to %s, size '%llu'",fd->name, fullpath, *psize); + free(path); + return MSG_OK; + } + else + XBT_WARN("File %s doesn't exist", fd->name); + return MSG_TASK_CANCELED; + } + else + { + XBT_WARN("New full path %s is not on the same mount point: %s. Action has been canceled.", fullpath, fd->mount); + return MSG_TASK_CANCELED; + } +} + + sg_size_t Workstation::getFreeSize(const char* name) { StoragePtr st = findStorageOnMountList(name); diff --git a/src/surf/workstation_interface.hpp b/src/surf/workstation_interface.hpp index 0b59b94f2c..473b044a09 100644 --- a/src/surf/workstation_interface.hpp +++ b/src/surf/workstation_interface.hpp @@ -369,6 +369,17 @@ public: */ virtual int fileSeek(surf_file_t fd, sg_size_t offset, int origin); + /** + * @brief Move a file to another location on the *same mount point*. + * @details [long description] + * + * @param fd The file descriptor + * @param fullpath The new full path + * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new + * full path is not on the same mount point + */ + virtual int fileMove(surf_file_t fd, const char* fullpath); + xbt_dynar_t p_storage; RoutingEdgePtr p_netElm; CpuPtr p_cpu; -- 2.20.1