Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add MSG_file_tell function and prepare MSG_file_seek
authorPierre Veyre <pierre.veyre@cc.in2p3.fr>
Fri, 29 Nov 2013 11:26:32 +0000 (12:26 +0100)
committerPierre Veyre <pierre.veyre@cc.in2p3.fr>
Fri, 29 Nov 2013 11:28:40 +0000 (12:28 +0100)
13 files changed:
include/msg/msg.h
include/simgrid/simix.h
src/include/surf/surf.h
src/msg/msg_io.c
src/simix/smx_io.c
src/simix/smx_io_private.h
src/simix/smx_smurf_private.h
src/simix/smx_user.c
src/surf/storage.cpp
src/surf/storage.hpp
src/surf/surf_interface.cpp
src/surf/workstation.cpp
src/surf/workstation.hpp

index c26b742..4ff877e 100644 (file)
@@ -92,7 +92,8 @@ XBT_PUBLIC(sg_size_t) MSG_file_get_size(msg_file_t fd);
 XBT_PUBLIC(void) MSG_file_dump(msg_file_t fd);
 XBT_PUBLIC(int) MSG_file_unlink(msg_file_t fd);
 XBT_PUBLIC(xbt_dict_t) MSG_file_ls(const char *mount, const char *path);
 XBT_PUBLIC(void) MSG_file_dump(msg_file_t fd);
 XBT_PUBLIC(int) MSG_file_unlink(msg_file_t fd);
 XBT_PUBLIC(xbt_dict_t) MSG_file_ls(const char *mount, const char *path);
-XBT_PUBLIC(msg_error_t) MSG_file_seek(msg_file_t fd, sg_size_t offset, int whence);
+XBT_PUBLIC(msg_error_t) MSG_file_seek(msg_file_t fd, sg_size_t offset, int origin);
+XBT_PUBLIC(sg_size_t) MSG_file_tell (msg_file_t fd);
 XBT_PUBLIC(void) __MSG_file_get_info(msg_file_t fd);
 /************************** Storage handling ***********************************/
 XBT_PUBLIC(msg_host_t) MSG_get_storage_by_name(const char *name);
 XBT_PUBLIC(void) __MSG_file_get_info(msg_file_t fd);
 /************************** Storage handling ***********************************/
 XBT_PUBLIC(msg_host_t) MSG_get_storage_by_name(const char *name);
index 62df978..c061398 100644 (file)
@@ -513,6 +513,7 @@ XBT_PUBLIC(int) simcall_file_unlink(smx_file_t fd);
 XBT_PUBLIC(xbt_dict_t) simcall_file_ls(const char* mount, const char* path);
 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(xbt_dict_t) simcall_file_ls(const char* mount, const char* path);
 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);
 /*****************************   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);
 /*****************************   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);
index dfcc808..cc267e6 100644 (file)
@@ -270,6 +270,7 @@ xbt_dict_t surf_workstation_get_storage_list(surf_resource_t workstation);
 int surf_workstation_unlink(surf_resource_t workstation, surf_file_t fd);
 surf_action_t surf_workstation_ls(surf_resource_t workstation, const char* mount, const char *path);
 size_t surf_workstation_get_size(surf_resource_t workstation, surf_file_t fd);
 int surf_workstation_unlink(surf_resource_t workstation, surf_file_t fd);
 surf_action_t surf_workstation_ls(surf_resource_t workstation, const char* mount, const char *path);
 size_t surf_workstation_get_size(surf_resource_t workstation, surf_file_t fd);
+size_t surf_workstation_file_tell(surf_resource_t workstation, surf_file_t fd);
 int surf_network_link_is_shared(surf_cpp_resource_t link);
 double surf_network_link_get_bandwidth(surf_cpp_resource_t link);
 double surf_network_link_get_latency(surf_cpp_resource_t link);
 int surf_network_link_is_shared(surf_cpp_resource_t link);
 double surf_network_link_get_bandwidth(surf_cpp_resource_t link);
 double surf_network_link_get_latency(surf_cpp_resource_t link);
index fcb8f76..3703c68 100644 (file)
@@ -160,7 +160,7 @@ int MSG_file_unlink(msg_file_t fd)
  * \brief Return the size of a file
  *
  * \param fd is the file descriptor (#msg_file_t)
  * \brief Return the size of a file
  *
  * \param fd is the file descriptor (#msg_file_t)
- * \return the size of the file (as a sg_size_t)
+ * \return the size of the file (as a #sg_size_t)
  */
 sg_size_t MSG_file_get_size(msg_file_t fd){
   return simcall_file_get_size(fd->simdata->smx_file);
  */
 sg_size_t MSG_file_get_size(msg_file_t fd){
   return simcall_file_get_size(fd->simdata->smx_file);
@@ -191,15 +191,41 @@ xbt_dict_t MSG_file_ls(const char *mount, const char *path)
 }
 
 /*
 }
 
 /*
- * Set the file position indicator in the msg_file_t by adding offset bytes
- * to the position specified by whence (either SEEK_SET, SEEK_CUR, or SEEK_END).
+ * \ingroup msg_file_management
+ * \brief Set the file position indicator in the msg_file_t by adding offset bytes
+ * to the position specified by origin (either SEEK_SET, SEEK_CUR, or SEEK_END).
+ *
+ * \param fd : file object that identifies the stream
+ * \param offset : number of bytes to offset from origin
+ * \param origin : Position used as reference for the offset. It is specified by
+ * one of the following constants defined in <cstdio> exclusively to be used as
+ * arguments for this function (SEEK_SET = beginning of file, SEEK_CUR = current
+ * position of the file pointer, SEEK_END = end of file)
+ *
+ * \return If successful, the function returns MSG_OK (=0). Otherwise, it returns
+ * MSG_TASK_CANCELED (=8).
+ *
  */
  */
-msg_error_t MSG_file_seek (msg_file_t fd, sg_size_t offset, int whence)
+msg_error_t MSG_file_seek(msg_file_t fd, sg_size_t offset, int origin)
 {
   THROW_UNIMPLEMENTED;
   return MSG_OK;
 }
 
 {
   THROW_UNIMPLEMENTED;
   return MSG_OK;
 }
 
+/*
+ * \ingroup msg_file_management
+ * \brief Returns the current value of the position indicator of the file
+ *
+ * \param fd : file object that identifies the stream
+ * \return On success, the current value of the position indicator is returned.
+ *
+ */
+sg_size_t MSG_file_tell(msg_file_t fd)
+{
+  return simcall_file_tell(fd->simdata->smx_file);
+}
+
+
 /********************************* Storage **************************************/
 
 /** @addtogroup msg_storage_management
 /********************************* Storage **************************************/
 
 /** @addtogroup msg_storage_management
@@ -349,7 +375,9 @@ sg_size_t MSG_storage_get_size(msg_storage_t storage)
 }
 
 /*
 }
 
 /*
- * Rename the file in the contents of its associated 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)
 {
  */
 msg_error_t MSG_storage_file_rename(msg_storage_t storage, const char* src,  const char* dest)
 {
@@ -358,7 +386,8 @@ msg_error_t MSG_storage_file_rename(msg_storage_t storage, const char* src,  con
 }
 
 /*
 }
 
 /*
- * Move a file to another location. Depending on the values of dest, dest, mount,
+ * \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.
  *
  * and fullname, this move can be local or remote and, within a host, on the same
  * mounted disk or between mounted disks.
  *
index 9f1585b..8d9ef2c 100644 (file)
@@ -279,6 +279,18 @@ sg_size_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd)
   return  surf_workstation_get_size(host, fd->surf_file);
 }
 
   return  surf_workstation_get_size(host, fd->surf_file);
 }
 
+sg_size_t SIMIX_pre_file_tell(smx_simcall_t simcall, smx_file_t fd)
+{
+  return SIMIX_file_tell(simcall->issuer, fd);
+}
+
+sg_size_t SIMIX_file_tell(smx_process_t process, smx_file_t fd)
+{
+  smx_host_t host = process->smx_host;
+  return  surf_workstation_file_tell(host, fd->surf_file);
+}
+
+
 xbt_dynar_t SIMIX_pre_file_get_info(smx_simcall_t simcall, smx_file_t fd)
 {
   return SIMIX_file_get_info(simcall->issuer, fd);
 xbt_dynar_t SIMIX_pre_file_get_info(smx_simcall_t simcall, smx_file_t fd)
 {
   return SIMIX_file_get_info(simcall->issuer, fd);
index 88eee72..904ba9b 100644 (file)
@@ -33,6 +33,7 @@ int SIMIX_pre_file_unlink(smx_simcall_t simcall, smx_file_t fd);
 void SIMIX_pre_file_ls(smx_simcall_t simcall,
                        const char* mount, const char* path);
 sg_size_t SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd);
 void SIMIX_pre_file_ls(smx_simcall_t simcall,
                        const char* mount, const char* path);
 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);
 void SIMIX_pre_storage_file_rename(smx_simcall_t simcall,smx_storage_t storage, const char* src, const char* dest);
 
 xbt_dynar_t SIMIX_pre_file_get_info(smx_simcall_t simcall, smx_file_t fd);
 void SIMIX_pre_storage_file_rename(smx_simcall_t simcall,smx_storage_t storage, const char* src, const char* dest);
 
@@ -47,6 +48,7 @@ int SIMIX_file_unlink(smx_process_t process, smx_file_t fd);
 smx_action_t SIMIX_file_ls(smx_process_t process, const char *mount,
                            const char *path);
 sg_size_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd);
 smx_action_t SIMIX_file_ls(smx_process_t process, const char *mount,
                            const char *path);
 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);
 void SIMIX_storage_file_rename(smx_process_t process, smx_storage_t storage, const char* src, const char* dest);
 
 xbt_dynar_t SIMIX_file_get_info(smx_process_t process, smx_file_t fd);
 void SIMIX_storage_file_rename(smx_process_t process, smx_storage_t storage, const char* src, const char* dest);
 
index 2e5b735..ccdbbfa 100644 (file)
@@ -391,6 +391,7 @@ ACTION(SIMCALL_FILE_CLOSE, file_close, WITHOUT_ANSWER, TINT(result), TDSPEC(fd,
 ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITH_ANSWER, TINT(result), TDSPEC(fd, smx_file_t)) sep \
 ACTION(SIMCALL_FILE_LS, file_ls, WITHOUT_ANSWER, TDSPEC(result, xbt_dict_t), TSTRING(mount), TSTRING(path)) sep \
 ACTION(SIMCALL_FILE_GET_SIZE, file_get_size, WITH_ANSWER, TSGSIZE(result), TDSPEC(fd, smx_file_t)) sep \
 ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITH_ANSWER, TINT(result), TDSPEC(fd, smx_file_t)) sep \
 ACTION(SIMCALL_FILE_LS, file_ls, WITHOUT_ANSWER, TDSPEC(result, xbt_dict_t), TSTRING(mount), TSTRING(path)) sep \
 ACTION(SIMCALL_FILE_GET_SIZE, file_get_size, WITH_ANSWER, TSGSIZE(result), TDSPEC(fd, smx_file_t)) sep \
+ACTION(SIMCALL_FILE_TELL, file_tell, WITH_ANSWER, TSGSIZE(result), TDSPEC(fd, smx_file_t)) sep \
 ACTION(SIMCALL_FILE_GET_INFO, file_get_info, WITH_ANSWER, TDSPEC(result, xbt_dynar_t), TDSPEC(fd, smx_file_t)) sep \
 ACTION(SIMCALL_STORAGE_FILE_RENAME, storage_file_rename, WITH_ANSWER, TVOID(result), TDSPEC(storage, smx_storage_t), TSTRING(src), TSTRING(dest)) sep \
 ACTION(SIMCALL_STORAGE_GET_FREE_SIZE, storage_get_free_size, WITH_ANSWER, TSGSIZE(result), TSTRING(name)) sep \
 ACTION(SIMCALL_FILE_GET_INFO, file_get_info, WITH_ANSWER, TDSPEC(result, xbt_dynar_t), TDSPEC(fd, smx_file_t)) sep \
 ACTION(SIMCALL_STORAGE_FILE_RENAME, storage_file_rename, WITH_ANSWER, TVOID(result), TDSPEC(storage, smx_storage_t), TSTRING(src), TSTRING(dest)) sep \
 ACTION(SIMCALL_STORAGE_GET_FREE_SIZE, storage_get_free_size, WITH_ANSWER, TSGSIZE(result), TSTRING(name)) sep \
index 929a8e0..1d6dc6d 100644 (file)
@@ -1474,10 +1474,18 @@ xbt_dict_t simcall_file_ls(const char* mount, const char* path)
  * \ingroup simix_file_management
  *
  */
  * \ingroup simix_file_management
  *
  */
-sg_size_t simcall_file_get_size (smx_file_t fd){
+sg_size_t simcall_file_get_size(smx_file_t fd){
   return simcall_BODY_file_get_size(fd);
 }
 
   return simcall_BODY_file_get_size(fd);
 }
 
+/**
+ * \ingroup simix_file_management
+ *
+ */
+sg_size_t simcall_file_tell(smx_file_t fd){
+  return simcall_BODY_file_tell(fd);
+}
+
 /**
  * \ingroup simix_file_management
  *
 /**
  * \ingroup simix_file_management
  *
index 2627dd8..a7e6b7c 100644 (file)
@@ -512,6 +512,7 @@ StorageActionPtr StorageLmm::open(const char* mount, const char* path)
   file->name = xbt_strdup(path);
   file->size = size;
   file->mount = xbt_strdup(mount);
   file->name = xbt_strdup(path);
   file->size = size;
   file->mount = xbt_strdup(mount);
+  file->current_position = 0;
 
   StorageActionLmmPtr action = new StorageActionLmm(p_model, 0, p_stateCurrent != SURF_RESOURCE_ON, this, OPEN);
   action->p_file = file;
 
   StorageActionLmmPtr action = new StorageActionLmm(p_model, 0, p_stateCurrent != SURF_RESOURCE_ON, this, OPEN);
   action->p_file = file;
@@ -542,8 +543,13 @@ StorageActionPtr StorageLmm::close(surf_file_t fd)
 
 StorageActionPtr StorageLmm::read(surf_file_t fd, sg_size_t size)
 {
 
 StorageActionPtr StorageLmm::read(surf_file_t fd, sg_size_t size)
 {
-  if(size > fd->size)
+  if(size > fd->size){
     size = fd->size;
     size = fd->size;
+    fd->current_position = fd->size;
+  }
+  else
+       fd->current_position += size;
+
   StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, READ);
   return action;
 }
   StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, READ);
   return action;
 }
@@ -555,7 +561,7 @@ StorageActionPtr StorageLmm::write(surf_file_t fd, sg_size_t size)
 
   StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, WRITE);
   action->p_file = fd;
 
   StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, WRITE);
   action->p_file = fd;
-
+  fd->current_position += size;
   // If the storage is full
   if(m_usedSize==m_size) {
     action->setState(SURF_ACTION_FAILED);
   // If the storage is full
   if(m_usedSize==m_size) {
     action->setState(SURF_ACTION_FAILED);
index d1b58dc..8915014 100644 (file)
@@ -147,6 +147,7 @@ typedef struct surf_file {
   char *name;
   char *mount;
   sg_size_t size;
   char *name;
   char *mount;
   sg_size_t size;
+  sg_size_t current_position;
 } s_surf_file_t;
 
 
 } s_surf_file_t;
 
 
index 24a8f2c..1b664f9 100644 (file)
@@ -369,6 +369,10 @@ sg_size_t surf_workstation_get_used_size(surf_resource_t resource, const char* n
   return get_casted_workstation(resource)->getUsedSize(name);
 }
 
   return get_casted_workstation(resource)->getUsedSize(name);
 }
 
+size_t surf_workstation_file_tell(surf_resource_t workstation, surf_file_t fd){
+  return get_casted_workstation(workstation)->getSize(fd);
+}
+
 xbt_dynar_t surf_workstation_get_vms(surf_resource_t resource){
   return get_casted_workstation(resource)->getVms();
 }
 xbt_dynar_t surf_workstation_get_vms(surf_resource_t resource){
   return get_casted_workstation(resource)->getVms();
 }
index ea90f8b..ff9c71a 100644 (file)
@@ -376,6 +376,10 @@ xbt_dynar_t WorkstationCLM03::getInfo( surf_file_t fd)
   return info;
 }
 
   return info;
 }
 
+sg_size_t WorkstationCLM03::fileTell(surf_file_t fd){
+  return fd->current_position;
+}
+
 sg_size_t WorkstationCLM03::getFreeSize(const char* name)
 {
   StoragePtr st = findStorageOnMountList(name);
 sg_size_t WorkstationCLM03::getFreeSize(const char* name)
 {
   StoragePtr st = findStorageOnMountList(name);
index 8ce487e..601040b 100644 (file)
@@ -90,6 +90,7 @@ public:
   ActionPtr read(surf_file_t fd, sg_size_t size);
   ActionPtr write(surf_file_t fd, sg_size_t size);
   xbt_dynar_t getInfo( surf_file_t fd);
   ActionPtr read(surf_file_t fd, sg_size_t size);
   ActionPtr write(surf_file_t fd, sg_size_t size);
   xbt_dynar_t getInfo( surf_file_t fd);
+  sg_size_t fileTell(surf_file_t fd);
   sg_size_t getFreeSize(const char* name);
   sg_size_t getUsedSize(const char* name);
 
   sg_size_t getFreeSize(const char* name);
   sg_size_t getUsedSize(const char* name);