Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add MSG_file_rename function
authorPierre Veyre <pierre.veyre@cc.in2p3.fr>
Fri, 8 Nov 2013 08:56:05 +0000 (09:56 +0100)
committerPierre Veyre <pierre.veyre@cc.in2p3.fr>
Fri, 8 Nov 2013 08:56:05 +0000 (09:56 +0100)
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/workstation.c

index 144d42b..5976cc3 100644 (file)
@@ -94,7 +94,7 @@ 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_move (msg_file_t fd, msg_host_t dest, char* mount, char* fullname);
 XBT_PUBLIC(msg_error_t) MSG_file_seek (msg_file_t fd, sg_storage_size_t offset, int whence);
 XBT_PUBLIC(xbt_dict_t) MSG_file_ls(const char *mount, const char *path);
 XBT_PUBLIC(msg_error_t) MSG_file_move (msg_file_t fd, msg_host_t dest, char* mount, char* fullname);
 XBT_PUBLIC(msg_error_t) MSG_file_seek (msg_file_t fd, sg_storage_size_t offset, int whence);
-XBT_PUBLIC(msg_error_t) MSG_file_rename (msg_file_t fd, char* new_name);
+XBT_PUBLIC(msg_error_t) MSG_file_rename (msg_file_t fd, const char* new_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);
 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 ecdd1d6..b595bf6 100644 (file)
@@ -489,7 +489,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_storage_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_storage_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(void) simcall_file_rename(smx_file_t fd, const char* new_name);
 /*****************************   Storage   **********************************/
 XBT_PUBLIC(sg_storage_size_t) simcall_storage_get_free_size (const char* name);
 XBT_PUBLIC(sg_storage_size_t) simcall_storage_get_used_size (const char* name);
 /*****************************   Storage   **********************************/
 XBT_PUBLIC(sg_storage_size_t) simcall_storage_get_free_size (const char* name);
 XBT_PUBLIC(sg_storage_size_t) simcall_storage_get_used_size (const char* name);
index 0f0694a..cce0dd9 100644 (file)
@@ -287,7 +287,7 @@ typedef struct surf_workstation_model_extension_public {
   surf_action_t(*ls) (void *workstation, const char* mount, const char *path);
   sg_storage_size_t (*get_size) (void *workstation, surf_file_t fd);
   xbt_dynar_t (*get_info) (void *workstation, surf_file_t fd);
   surf_action_t(*ls) (void *workstation, const char* mount, const char *path);
   sg_storage_size_t (*get_size) (void *workstation, surf_file_t fd);
   xbt_dynar_t (*get_info) (void *workstation, surf_file_t fd);
-
+  void (*rename) (void *workstation, surf_file_t fd, const char *new_name);
   int (*link_shared) (const void *link);
   xbt_dict_t(*get_properties) (const void *resource);
   void (*add_traces) (void);
   int (*link_shared) (const void *link);
   xbt_dict_t(*get_properties) (const void *resource);
   void (*add_traces) (void);
index cb2018a..1aa60ef 100644 (file)
@@ -216,9 +216,9 @@ msg_error_t MSG_file_seek (msg_file_t fd, sg_storage_size_t offset, int whence)
 /*
  * Rename the file in the contents of its associated storage.
  */
 /*
  * Rename the file in the contents of its associated storage.
  */
-msg_error_t MSG_file_rename (msg_file_t fd, char* new_name)
+msg_error_t MSG_file_rename (msg_file_t fd, const char* new_name)
 {
 {
-  THROW_UNIMPLEMENTED;
+  simcall_file_rename(fd->simdata->smx_file, new_name);
   return MSG_OK;
 }
 
   return MSG_OK;
 }
 
index 07a354c..aa0d016 100644 (file)
@@ -300,6 +300,19 @@ xbt_dynar_t SIMIX_file_get_info(smx_process_t process, smx_file_t fd)
       fd->surf_file);
 }
 
       fd->surf_file);
 }
 
+void SIMIX_pre_file_rename(smx_simcall_t simcall, smx_file_t fd, const char* new_name)
+{
+  return SIMIX_file_rename(simcall->issuer, fd, new_name);
+}
+
+void SIMIX_file_rename(smx_process_t process, smx_file_t fd, const char* new_name)
+{
+  smx_host_t host = process->smx_host;
+  return  surf_workstation_model->extension.workstation.rename(host,
+      fd->surf_file, new_name);
+}
+
+
 sg_storage_size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall, const char* name)
 {
   return SIMIX_storage_get_free_size(simcall->issuer, name);
 sg_storage_size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall, const char* name)
 {
   return SIMIX_storage_get_free_size(simcall->issuer, name);
index a3fea00..2e01b20 100644 (file)
@@ -34,6 +34,7 @@ void SIMIX_pre_file_ls(smx_simcall_t simcall,
                        const char* mount, const char* path);
 sg_storage_size_t SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd);
 xbt_dynar_t SIMIX_pre_file_get_info(smx_simcall_t simcall, smx_file_t fd);
                        const char* mount, const char* path);
 sg_storage_size_t SIMIX_pre_file_get_size(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_file_rename(smx_simcall_t simcall, smx_file_t fd, const char* new_name);
 
 void* SIMIX_file_get_data(smx_file_t fd);
 void SIMIX_file_set_data(smx_file_t fd, void *data);
 
 void* SIMIX_file_get_data(smx_file_t fd);
 void SIMIX_file_set_data(smx_file_t fd, void *data);
@@ -47,6 +48,7 @@ smx_action_t SIMIX_file_ls(smx_process_t process, const char *mount,
                            const char *path);
 sg_storage_size_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd);
 xbt_dynar_t SIMIX_file_get_info(smx_process_t process, smx_file_t fd);
                            const char *path);
 sg_storage_size_t SIMIX_file_get_size(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_file_rename(smx_process_t process, smx_file_t fd, const char* new_name);
 
 sg_storage_size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall,const char* name);
 sg_storage_size_t SIMIX_storage_get_free_size(smx_process_t process,const char* name);
 
 sg_storage_size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall,const char* name);
 sg_storage_size_t SIMIX_storage_get_free_size(smx_process_t process,const char* name);
index 1e191f7..f3b01fd 100644 (file)
@@ -357,6 +357,7 @@ ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITH_ANSWER, TINT(result), TSPEC(fd, sm
 ACTION(SIMCALL_FILE_LS, file_ls, WITHOUT_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(mount), TSTRING(path)) sep \
 ACTION(SIMCALL_FILE_GET_SIZE, file_get_size, WITH_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t)) sep \
 ACTION(SIMCALL_FILE_GET_INFO, file_get_info, WITH_ANSWER, TSPEC(result, xbt_dynar_t), TSPEC(fd, smx_file_t)) sep \
 ACTION(SIMCALL_FILE_LS, file_ls, WITHOUT_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(mount), TSTRING(path)) sep \
 ACTION(SIMCALL_FILE_GET_SIZE, file_get_size, WITH_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t)) sep \
 ACTION(SIMCALL_FILE_GET_INFO, file_get_info, WITH_ANSWER, TSPEC(result, xbt_dynar_t), TSPEC(fd, smx_file_t)) sep \
+ACTION(SIMCALL_FILE_RENAME, file_rename, WITH_ANSWER, TVOID(result), TSPEC(fd, smx_file_t), TSTRING(new_name)) sep \
 ACTION(SIMCALL_STORAGE_GET_FREE_SIZE, storage_get_free_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \
 ACTION(SIMCALL_STORAGE_GET_USED_SIZE, storage_get_used_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \
 ACTION(SIMCALL_STORAGE_GET_PROPERTIES, storage_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(storage, smx_storage_t)) sep \
 ACTION(SIMCALL_STORAGE_GET_FREE_SIZE, storage_get_free_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \
 ACTION(SIMCALL_STORAGE_GET_USED_SIZE, storage_get_used_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \
 ACTION(SIMCALL_STORAGE_GET_PROPERTIES, storage_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(storage, smx_storage_t)) sep \
index a4453a8..a8d7f4c 100644 (file)
@@ -1273,6 +1273,15 @@ xbt_dynar_t simcall_file_get_info(smx_file_t fd)
   return simcall_BODY_file_get_info(fd);
 }
 
   return simcall_BODY_file_get_info(fd);
 }
 
+/**
+ * \ingroup simix_file_management
+ *
+ */
+void simcall_file_rename(smx_file_t fd, const char* new_name)
+{
+  return simcall_BODY_file_rename(fd, new_name);
+}
+
 /**
  * \ingroup simix_storage_management
  * \brief Returns the free space size on a given storage element.
 /**
  * \ingroup simix_storage_management
  * \brief Returns the free space size on a given storage element.
index f50cf05..c986d51 100644 (file)
@@ -11,6 +11,7 @@
 #include "storage_private.h"
 #include "surf/surf_resource.h"
 #include "simgrid/sg_config.h"
 #include "storage_private.h"
 #include "surf/surf_resource.h"
 #include "simgrid/sg_config.h"
+#include <inttypes.h>
 
 typedef struct workstation_CLM03 {
   s_surf_resource_t generic_resource;   /* Must remain first to add this to a trace */
 
 typedef struct workstation_CLM03 {
   s_surf_resource_t generic_resource;   /* Must remain first to add this to a trace */
@@ -473,6 +474,34 @@ static xbt_dynar_t ws_file_get_info(void *workstation, surf_file_t fd)
   return info;
 }
 
   return info;
 }
 
+static void ws_file_rename(void *workstation, surf_file_t fd, const char* new_name)
+{
+  storage_t storage = find_storage_on_mount_list(workstation, fd->mount);
+
+  const char* old_full_name = fd->name;
+  xbt_dynar_t dyn = NULL;
+  const char* separator;
+  const char* ctype = storage->content_type;
+
+  // TODO: PV: use an enum and a switch case to manage content type properly
+  if(!strcmp(ctype, "txt_unix"))
+       separator = strdup("/");
+  else
+       separator = strdup("\\");
+
+  // Split file with separator and replace file name
+  dyn = xbt_str_split(old_full_name, separator);
+  xbt_dynar_pop_ptr(dyn);
+  xbt_dynar_push(dyn, &new_name);
+  char *new_full_name = xbt_str_join(dyn, separator);
+
+  sg_storage_size_t *psize;
+  psize = (sg_storage_size_t*) xbt_dict_get_or_null(storage->content,old_full_name);
+  xbt_dict_remove(storage->content, old_full_name);
+  xbt_dict_set(storage->content,new_full_name,psize,NULL);
+  XBT_DEBUG("Change file name from %s to %s, size '%" PRIu64 "'",fd->name, new_full_name, *psize);
+}
+
 static sg_storage_size_t ws_storage_get_free_size(void *workstation,const char* name)
 {
   storage_t st = find_storage_on_mount_list(workstation, name);
 static sg_storage_size_t ws_storage_get_free_size(void *workstation,const char* name)
 {
   storage_t st = find_storage_on_mount_list(workstation, name);
@@ -551,6 +580,7 @@ static void surf_workstation_model_init_internal(void)
   surf_workstation_model->extension.workstation.ls = ws_action_ls;
   surf_workstation_model->extension.workstation.get_size = ws_file_get_size;
   surf_workstation_model->extension.workstation.get_info = ws_file_get_info;
   surf_workstation_model->extension.workstation.ls = ws_action_ls;
   surf_workstation_model->extension.workstation.get_size = ws_file_get_size;
   surf_workstation_model->extension.workstation.get_info = ws_file_get_info;
+  surf_workstation_model->extension.workstation.rename = ws_file_rename;
   surf_workstation_model->extension.workstation.get_free_size = ws_storage_get_free_size;
   surf_workstation_model->extension.workstation.get_used_size = ws_storage_get_used_size;
   surf_workstation_model->extension.workstation.get_storage_list = ws_get_storage_list;
   surf_workstation_model->extension.workstation.get_free_size = ws_storage_get_free_size;
   surf_workstation_model->extension.workstation.get_used_size = ws_storage_get_used_size;
   surf_workstation_model->extension.workstation.get_storage_list = ws_get_storage_list;