X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f60c6c67576ca97e84d781811f9076c18f183b11..8199067e1f2a6ea4d3d8a38df1a4fb3f25d364da:/src/msg/msg_io.c diff --git a/src/msg/msg_io.c b/src/msg/msg_io.c index 3f7e1f89d2..a35e59899b 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -140,7 +140,7 @@ sg_size_t MSG_file_read(msg_file_t fd, sg_size_t size) sg_size_t MSG_file_write(msg_file_t fd, sg_size_t size) { msg_file_priv_t file_priv = MSG_file_priv(fd); - sg_size_t write_size; + sg_size_t write_size, offset; /* Find the host where the file is physically located (remote or local)*/ msg_storage_t storage_src =(msg_storage_t) xbt_lib_get_elm_or_null(storage_lib, file_priv->storageId); @@ -172,7 +172,9 @@ sg_size_t MSG_file_write(msg_file_t fd, sg_size_t size) } } /* Write file on local or remote host */ + offset = simcall_file_tell(file_priv->simdata->smx_file); write_size = simcall_file_write(file_priv->simdata->smx_file, size, attached_host); + file_priv->size = offset+write_size; return write_size; } @@ -187,27 +189,20 @@ sg_size_t MSG_file_write(msg_file_t fd, sg_size_t size) */ msg_file_t MSG_file_open(const char* fullpath, void* data) { + char *name; msg_file_priv_t priv = xbt_new(s_msg_file_priv_t, 1); priv->data = data; priv->fullpath = xbt_strdup(fullpath); priv->simdata = xbt_new0(s_simdata_file_t,1); priv->simdata->smx_file = simcall_file_open(fullpath, MSG_host_self()); - xbt_lib_set(file_lib, fullpath, MSG_FILE_LEVEL, priv); - msg_file_t fd = (msg_file_t) xbt_lib_get_elm_or_null(file_lib, fullpath); + name = bprintf("%s:%i:%s",MSG_host_get_name(MSG_host_self()),MSG_process_self_PID(),fullpath); + xbt_lib_set(file_lib, name, MSG_FILE_LEVEL, priv); + msg_file_t fd = (msg_file_t) xbt_lib_get_elm_or_null(file_lib, name); __MSG_file_get_info(fd); - + xbt_free(name); return fd; } -/** - * \brief Frees private data of a file (internal call only) - */ -void __MSG_file_priv_free(msg_file_priv_t priv) -{ - xbt_free(&priv->simdata->smx_file); - free(priv); -} - /** \ingroup msg_file_management * \brief Close the file * @@ -216,9 +211,15 @@ void __MSG_file_priv_free(msg_file_priv_t priv) */ int MSG_file_close(msg_file_t fd) { + char *name; msg_file_priv_t priv = MSG_file_priv(fd); + if (priv->data) + xbt_free(priv->data); + int res = simcall_file_close(priv->simdata->smx_file, MSG_host_self()); - xbt_lib_unset(file_lib, priv->fullpath, MSG_FILE_LEVEL, 1); + name = bprintf("%s:%i:%s",MSG_host_get_name(MSG_host_self()),MSG_process_self_PID(),priv->fullpath); + xbt_lib_unset(file_lib, name, MSG_FILE_LEVEL, 1); + xbt_free(name); return res; } @@ -230,8 +231,14 @@ int MSG_file_close(msg_file_t fd) */ msg_error_t MSG_file_unlink(msg_file_t fd) { - msg_file_priv_t priv = MSG_file_priv(fd); - int res = simcall_file_unlink(priv->simdata->smx_file); + msg_file_priv_t file_priv = MSG_file_priv(fd); + /* Find the host where the file is physically located (remote or local)*/ + msg_storage_t storage_src = + (msg_storage_t) xbt_lib_get_elm_or_null(storage_lib, + file_priv->storageId); + msg_storage_priv_t storage_priv_src = MSG_storage_priv(storage_src); + msg_host_t attached_host = MSG_get_host_by_name(storage_priv_src->hostname); + int res = simcall_file_unlink(file_priv->simdata->smx_file, attached_host); return res; } @@ -262,7 +269,7 @@ sg_size_t MSG_file_get_size(msg_file_t fd){ * MSG_TASK_CANCELED (=8). * */ -msg_error_t MSG_file_seek(msg_file_t fd, sg_size_t offset, int origin) +msg_error_t MSG_file_seek(msg_file_t fd, sg_offset_t offset, int origin) { msg_file_priv_t priv = MSG_file_priv(fd); return simcall_file_seek(priv->simdata->smx_file, offset, origin); @@ -317,6 +324,7 @@ msg_error_t MSG_file_rcopy (msg_file_t file, msg_host_t host, const char* fullpa msg_storage_t storage_src =(msg_storage_t) xbt_lib_get_elm_or_null(storage_lib, file_priv->storageId); msg_storage_priv_t storage_priv_src = MSG_storage_priv(storage_src); msg_host_t attached_host = MSG_get_host_by_name(storage_priv_src->hostname); + MSG_file_seek(file, 0, SEEK_SET); read_size = simcall_file_read(file_priv->simdata->smx_file, file_priv->size, attached_host); /* Find the real host destination where the file will be physically stored */ @@ -339,6 +347,8 @@ msg_error_t MSG_file_rcopy (msg_file_t file, msg_host_t host, const char* fullpa } free(file_mount_name); } + xbt_dict_free(&storage_list); + if(longest_prefix_length>0){ /* Mount point found, retrieve the host the storage is attached to */ msg_storage_priv_t storage_dest_priv = MSG_storage_priv(storage_dest); @@ -443,20 +453,20 @@ const char *MSG_storage_get_name(msg_storage_t storage) { /** \ingroup msg_storage_management * \brief Returns the free space size of a storage element - * \param name the name of a storage + * \param storage a storage * \return the free space size of the storage element (as a #sg_size_t) */ -sg_size_t MSG_storage_get_free_size(const char* name){ - return simcall_storage_get_free_size(name); +sg_size_t MSG_storage_get_free_size(msg_storage_t storage){ + return simcall_storage_get_free_size(storage); } /** \ingroup msg_storage_management * \brief Returns the used space size of a storage element - * \param name the name of a storage + * \param storage a storage * \return the used space size of the storage element (as a #sg_size_t) */ -sg_size_t MSG_storage_get_used_size(const char* name){ - return simcall_storage_get_used_size(name); +sg_size_t MSG_storage_get_used_size(msg_storage_t storage){ + return simcall_storage_get_used_size(storage); } /** \ingroup msg_storage_management @@ -482,6 +492,19 @@ void MSG_storage_set_property_value(msg_storage_t storage, const char *name, cha xbt_dict_set(MSG_storage_get_properties(storage), name, value,free_ctn); } +/** \ingroup m_storage_management + * \brief Returns the value of a given storage property + * + * \param storage a storage + * \param name a property name + * \return value of a property (or NULL if property not set) + */ +const char *MSG_storage_get_property_value(msg_storage_t storage, const char *name) +{ + return xbt_dict_get_or_null(MSG_storage_get_properties(storage), name); +} + + /** \ingroup msg_storage_management * \brief Finds a msg_storage_t using its name. * \param name the name of a storage @@ -550,6 +573,12 @@ xbt_dict_t MSG_storage_get_content(msg_storage_t storage) return SIMIX_storage_get_content(storage); } +/** \ingroup msg_storage_management + * + * \brief Returns the size of a #msg_storage_t. + * \param storage a storage + * \return The size of the storage + */ sg_size_t MSG_storage_get_size(msg_storage_t storage) { return SIMIX_storage_get_size(storage);