/** \ingroup msg_file_management * \brief Write into a file (local or remote) * * \param size of the file to write * \param fd is a the file descriptor * \return the number of bytes successfully write or -1 if an error occurred */ 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, 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); 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); if(strcmp(storage_priv_src->hostname, MSG_host_get_name(MSG_host_self()))){ /* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */ XBT_DEBUG("File is on %s remote host, initiate data transfer of %llu bytes.", storage_priv_src->hostname, size); msg_host_t *m_host_list = NULL; m_host_list = calloc(2, sizeof(msg_host_t)); m_host_list[0] = MSG_host_self(); m_host_list[1] = attached_host; double flops_amount[] = { 0, 0 }; double bytes_amount[] = { 0, (double)size, 0, 0 }; msg_task_t task = MSG_parallel_task_create("file transfer for write", 2, m_host_list, flops_amount, bytes_amount, NULL); msg_error_t transfer = MSG_parallel_task_execute(task); MSG_task_destroy(task); free(m_host_list); if(transfer != MSG_OK){ if (transfer == MSG_HOST_FAILURE) XBT_WARN("Transfer error, %s remote host just turned off!", MSG_host_get_name(attached_host)); if (transfer == MSG_TASK_CANCELED) XBT_WARN("Transfer error, task has been canceled!"); return -1; } } /* 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; }
sg_size_t File::write(sg_size_t size) { return simcall_file_write(p_inferior,size, Host::current()->inferior()); }