Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add MSG_file_seek function
authorPierre Veyre <pierre.veyre@cc.in2p3.fr>
Fri, 29 Nov 2013 13:41:37 +0000 (14:41 +0100)
committerPierre Veyre <pierre.veyre@cc.in2p3.fr>
Fri, 29 Nov 2013 13:41:37 +0000 (14:41 +0100)
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/surf_interface.cpp
src/surf/workstation.cpp
src/surf/workstation.hpp

index c061398..f33177f 100644 (file)
@@ -514,6 +514,7 @@ 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);
+XBT_PUBLIC(int) simcall_file_seek(smx_file_t fd, sg_size_t offset, int origin);
 /*****************************   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 cc267e6..c9b5fd6 100644 (file)
@@ -271,6 +271,7 @@ 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_workstation_file_seek(surf_resource_t workstation, surf_file_t fd, sg_size_t offset, int origin);
 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 3703c68..3638f9d 100644 (file)
@@ -208,8 +208,8 @@ xbt_dict_t MSG_file_ls(const char *mount, const char *path)
  */
 msg_error_t MSG_file_seek(msg_file_t fd, sg_size_t offset, int origin)
 {
-  THROW_UNIMPLEMENTED;
-  return MSG_OK;
+  //THROW_UNIMPLEMENTED;
+  return simcall_file_seek(fd->simdata->smx_file, offset, origin);
 }
 
 /*
index 8d9ef2c..fd61f37 100644 (file)
@@ -302,6 +302,17 @@ xbt_dynar_t SIMIX_file_get_info(smx_process_t process, smx_file_t fd)
   return  surf_workstation_get_info(host, fd->surf_file);
 }
 
+int SIMIX_pre_file_seek(smx_simcall_t simcall, smx_file_t fd, sg_size_t offset, int origin)
+{
+  return SIMIX_file_seek(simcall->issuer, fd, offset, origin);
+}
+
+int SIMIX_file_seek(smx_process_t process, smx_file_t fd, sg_size_t offset, int origin)
+{
+  smx_host_t host = process->smx_host;
+  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)
 {
   return SIMIX_storage_file_rename(simcall->issuer, storage, src, dest);
index 904ba9b..ddb1513 100644 (file)
@@ -35,6 +35,7 @@ void SIMIX_pre_file_ls(smx_simcall_t simcall,
 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);
 
 void* SIMIX_file_get_data(smx_file_t fd);
@@ -50,8 +51,9 @@ smx_action_t SIMIX_file_ls(smx_process_t process, const char *mount,
 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);
+int SIMIX_file_seek(smx_process_t process, smx_file_t fd, sg_size_t offset, int origin);
 
+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);
 
index ccdbbfa..915c890 100644 (file)
@@ -392,6 +392,7 @@ ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITH_ANSWER, TINT(result), TDSPEC(fd, s
 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_SEEK, file_seek, WITH_ANSWER, TINT(result), TDSPEC(fd, smx_file_t), TSGSIZE(offset), TINT(origin)) 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 1d6dc6d..8b75d4b 100644 (file)
@@ -1495,6 +1495,14 @@ xbt_dynar_t simcall_file_get_info(smx_file_t fd)
   return simcall_BODY_file_get_info(fd);
 }
 
+/**
+ * \ingroup simix_file_management
+ *
+ */
+int simcall_file_seek(smx_file_t fd, sg_size_t offset, int origin){
+  return simcall_BODY_file_seek(fd, offset, origin);
+}
+
 /**
  * \ingroup simix_file_management
  *
index 1b664f9..f2ac787 100644 (file)
@@ -370,7 +370,11 @@ sg_size_t surf_workstation_get_used_size(surf_resource_t resource, const char* n
 }
 
 size_t surf_workstation_file_tell(surf_resource_t workstation, surf_file_t fd){
-  return get_casted_workstation(workstation)->getSize(fd);
+  return get_casted_workstation(workstation)->fileTell(fd);
+}
+
+int surf_workstation_file_seek(surf_resource_t workstation, surf_file_t fd, sg_size_t offset, int origin){
+  return get_casted_workstation(workstation)->fileSeek(fd, offset, origin);
 }
 
 xbt_dynar_t surf_workstation_get_vms(surf_resource_t resource){
index ff9c71a..732883a 100644 (file)
@@ -380,6 +380,25 @@ sg_size_t WorkstationCLM03::fileTell(surf_file_t fd){
   return fd->current_position;
 }
 
+sg_size_t WorkstationCLM03::fileSeek(surf_file_t fd, sg_size_t offset, int origin){
+
+  switch (origin) {
+  case SEEK_SET:
+    fd->current_position = 0;
+       return MSG_OK;
+  case SEEK_CUR:
+       if(offset > fd->size)
+         offset = fd->size;
+       fd->current_position = offset;
+       return MSG_OK;
+  case SEEK_END:
+       fd->current_position = fd->size;
+       return MSG_OK;
+  default:
+       return MSG_TASK_CANCELED;
+  }
+}
+
 sg_size_t WorkstationCLM03::getFreeSize(const char* name)
 {
   StoragePtr st = findStorageOnMountList(name);
index 601040b..34768af 100644 (file)
@@ -93,6 +93,7 @@ public:
   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 fileSeek(surf_file_t fd, sg_size_t offset, int origin);
 
   bool isUsed();
   //bool isShared();