Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
updating the MSG vision of file size when writing
[simgrid.git] / src / msg / msg_io.c
index d5e1690..898604d 100644 (file)
@@ -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,13 +189,15 @@ 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[2048];
   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);
+  sprintf(name, "%s:%s",MSG_host_get_name(MSG_host_self()),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);
 
   return fd;
@@ -216,9 +220,11 @@ void __MSG_file_priv_free(msg_file_priv_t priv)
  */
 int MSG_file_close(msg_file_t fd)
 {
+  char name[2048];
   msg_file_priv_t priv = MSG_file_priv(fd);
   int res = simcall_file_close(priv->simdata->smx_file, MSG_host_self());
-  xbt_lib_unset(file_lib, priv->fullpath, MSG_FILE_LEVEL, 1);
+  sprintf(name, "%s:%s",MSG_host_get_name(MSG_host_self()),priv->fullpath);
+  xbt_lib_unset(file_lib, name, MSG_FILE_LEVEL, 1);
   return res;
 }
 
@@ -262,7 +268,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 +323,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 */
@@ -550,6 +557,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);