XBT_INFO("Write %llu bytes on %s", write, file_name);
MSG_file_dump(file);
- MSG_file_close(file);
- free(file_name);
-
storage_name = xbt_strdup("Disk4");
storage = MSG_storage_get_by_name(storage_name);
// Now rename file from ./tmp/data.txt to ./tmp/simgrid.readme
- XBT_INFO("*** Renaming '/tmp/data.txt' into '/tmp/simgrid.readme'");
- MSG_storage_file_rename(storage, "/tmp/data.txt", "/tmp/simgrid.readme");
+ XBT_INFO("*** Move '/tmp/data.txt' into '/tmp/simgrid.readme'");
+ MSG_file_move(file, "/home/tmp/simgrid.readme");
+
+ MSG_file_close(file);
+ free(file_name);
// Now attach some user data to disk1
XBT_INFO("*** Get/set data for storage element: %s ***",storage_name);
> Storage Id: 'Disk4'
> Storage Type: 'single_SSD'
> Content Type: 'txt_unix'
-> [ 0.007917] (1:(null)@denise) *** Renaming '/tmp/data.txt' into '/tmp/simgrid.readme'
+> [ 0.007917] (1:(null)@denise) *** Move '/tmp/data.txt' into '/tmp/simgrid.readme'
> [ 0.007917] (1:(null)@denise) *** Get/set data for storage element: Disk4 ***
> [ 0.007917] (1:(null)@denise) Get data: '(null)'
> [ 0.007917] (1:(null)@denise) Set and get data: 'Some user data'
XBT_PUBLIC(void) __MSG_file_get_info(msg_file_t fd);
XBT_PUBLIC(void) __MSG_file_priv_free(msg_file_priv_t priv);
XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t storage);
+XBT_PUBLIC(msg_error_t) MSG_file_move(msg_file_t fd, const char* fullpath);
/************************** Storage handling ***********************************/
XBT_PUBLIC(msg_host_t) MSG_get_storage_by_name(const char *name);
XBT_PUBLIC(const char *) MSG_storage_get_name(msg_storage_t storage);
XBT_PUBLIC(xbt_dict_t) MSG_storage_get_content(msg_storage_t storage);
XBT_PUBLIC(sg_size_t) MSG_storage_get_size(msg_storage_t storage);
XBT_PUBLIC(msg_error_t) MSG_storage_file_move(msg_file_t fd, msg_host_t dest, char* mount, char* fullname);
-XBT_PUBLIC(msg_error_t) MSG_storage_file_rename(msg_storage_t storage, const char* src, const char* dest);
XBT_PUBLIC(const char *) MSG_storage_get_host(msg_storage_t storage);
/************************** AS Router handling ************************************/
XBT_PUBLIC(const char *) MSG_as_router_get_property_value(const char* asr, const char *name);
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);
+XBT_PUBLIC(int) simcall_file_move(smx_file_t fd, const char* fullpath);
/***************************** 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);
XBT_PUBLIC(xbt_dict_t) simcall_storage_get_content(smx_storage_t storage);
XBT_PUBLIC(const char*) SIMIX_storage_get_name(smx_storage_t storage);
XBT_PUBLIC(sg_size_t) SIMIX_storage_get_size(smx_storage_t storage);
-XBT_PUBLIC(void) simcall_storage_file_rename(smx_storage_t storage, const char* src, const char* dest);
XBT_PUBLIC(const char*) SIMIX_storage_get_host(smx_storage_t storage);
/************************** AS router **********************************/
XBT_PUBLIC(xbt_dict_t) SIMIX_asr_get_properties(const char *name);
*/
XBT_PUBLIC(size_t) surf_workstation_file_tell(surf_resource_t workstation, surf_file_t fd);
+/**
+ * @brief Move a file to another location on the *same mount point*.
+ * @details [long description]
+ *
+ * @param workstation The surf workstation
+ * @param fd The file descriptor
+ * @param fullpath The new full path
+ * @param origin Position used as a reference for the offset
+ *
+ * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
+ */
+XBT_PUBLIC(int) surf_workstation_file_move(surf_resource_t workstation, surf_file_t fd, const char* fullpath);
+
/**
* @brief Set the position indictator assiociated with the file descriptor to a new position
* @details [long description]
*/
XBT_PUBLIC(int) surf_workstation_file_seek(surf_resource_t workstation, surf_file_t fd, sg_size_t offset, int origin);
+
/**
* @brief [brief description]
* @details [long description]
*/
XBT_PUBLIC(sg_size_t) surf_storage_get_size(surf_resource_t resource);
-/**
- * @brief Rename a path
- *
- * @param resource The surf storage
- * @param src The old path
- * @param dest The new path
- */
-XBT_PUBLIC(void) surf_storage_rename(surf_resource_t resource, const char* src, const char* dest);
-
/**
* @brief Get the data associated to the action
*
return priv->fullpath;
}
+/**
+ * \ingroup msg_file_management
+ * \brief Move a file to another location on the *same mount point*.
+ *
+ */
+msg_error_t MSG_file_move (msg_file_t fd, const char* fullpath)
+{
+ msg_file_priv_t priv = MSG_file_priv(fd);
+ return simcall_file_move(priv->simdata->smx_file, fullpath);
+}
-/*
+/**
* \brief Destroys a file (internal call only)
*/
void __MSG_file_destroy(msg_file_priv_t file) {
return xbt_lib_get_elm_or_null(storage_lib, name);
}
-/*
+/**
* \brief Destroys a storage (internal call only)
*/
void __MSG_storage_destroy(msg_storage_priv_t storage) {
return SIMIX_storage_get_size(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)
-{
- simcall_storage_file_rename(storage, src, dest);
- return MSG_OK;
-}
-
-/**
- * \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.
- *
- */
-msg_error_t MSG_storage_file_move (msg_file_t fd, msg_host_t dest, char* mount, char* fullname)
-{
- THROW_UNIMPLEMENTED;
- return MSG_OK;
-}
-
/** \ingroup msg_storage_management
*
* \brief Returns the host name the storage is attached to
file_tell True (sg_size_t) (fd, void*, smx_file_t)
file_seek True (int) (fd, void*, smx_file_t) (offset, sg_size_t) (origin, int)
file_get_info True (void*, xbt_dynar_t) (fd, void*, smx_file_t)
-storage_file_rename True (void) (storage, void*, smx_storage_t) (src, const char*) (dest, const char*)
+file_move True (int) (fd, void*, smx_file_t) (fullpath, const char*)
storage_get_free_size True (sg_size_t) (name, const char*)
storage_get_used_size True (sg_size_t) (name, const char*)
storage_get_properties True (void*, xbt_dict_t) (storage, void*, smx_storage_t)
static inline void simcall_file_get_info__set__fd(smx_simcall_t simcall, void* arg){
simcall->args[0].dp = arg;
}
-static inline smx_storage_t simcall_storage_file_rename__get__storage(smx_simcall_t simcall){
- return (smx_storage_t) simcall->args[0].dp;
+static inline smx_file_t simcall_file_move__get__fd(smx_simcall_t simcall){
+ return (smx_file_t) simcall->args[0].dp;
}
-static inline void simcall_storage_file_rename__set__storage(smx_simcall_t simcall, void* arg){
+static inline void simcall_file_move__set__fd(smx_simcall_t simcall, void* arg){
simcall->args[0].dp = arg;
}
-static inline const char* simcall_storage_file_rename__get__src(smx_simcall_t simcall){
+static inline const char* simcall_file_move__get__fullpath(smx_simcall_t simcall){
return simcall->args[1].cc;
}
-static inline void simcall_storage_file_rename__set__src(smx_simcall_t simcall, const char* arg){
+static inline void simcall_file_move__set__fullpath(smx_simcall_t simcall, const char* arg){
simcall->args[1].cc = arg;
}
-static inline const char* simcall_storage_file_rename__get__dest(smx_simcall_t simcall){
- return simcall->args[2].cc;
-}
-static inline void simcall_storage_file_rename__set__dest(smx_simcall_t simcall, const char* arg){
- simcall->args[2].cc = arg;
-}
static inline const char* simcall_storage_get_free_size__get__name(smx_simcall_t simcall){
return simcall->args[0].cc;
}
}
return self->simcall.result.dp;
}
- inline static void simcall_BODY_storage_file_rename(smx_storage_t storage, const char* src, const char* dest) {
+ inline static int simcall_BODY_file_move(smx_file_t fd, const char* fullpath) {
smx_process_t self = SIMIX_process_self();
- self->simcall.call = SIMCALL_STORAGE_FILE_RENAME;
+ self->simcall.call = SIMCALL_FILE_MOVE;
memset(&self->simcall.result, 0, sizeof(self->simcall.result));
memset(self->simcall.args, 0, sizeof(self->simcall.args));
- self->simcall.args[0].dp = (void*) storage;
- self->simcall.args[1].cc = (const char*) src;
- self->simcall.args[2].cc = (const char*) dest;
+ self->simcall.args[0].dp = (void*) fd;
+ self->simcall.args[1].cc = (const char*) fullpath;
if (self != simix_global->maestro_process) {
XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
} else {
SIMIX_simcall_pre(&self->simcall, 0);
}
-
+ return self->simcall.result.i;
}
inline static sg_size_t simcall_BODY_storage_get_free_size(const char* name) {
smx_process_t self = SIMIX_process_self();
SIMIX_simcall_answer(simcall);
break;
-case SIMCALL_STORAGE_FILE_RENAME:
- SIMIX_pre_storage_file_rename(simcall , (smx_storage_t) simcall->args[0].dp, simcall->args[1].cc, simcall->args[2].cc);
+case SIMCALL_FILE_MOVE:
+ simcall->result.i = SIMIX_pre_file_move(simcall , (smx_file_t) simcall->args[0].dp, simcall->args[1].cc);
SIMIX_simcall_answer(simcall);
break;
SIMCALL_FILE_TELL,
SIMCALL_FILE_SEEK,
SIMCALL_FILE_GET_INFO,
-SIMCALL_STORAGE_FILE_RENAME,
+SIMCALL_FILE_MOVE,
SIMCALL_STORAGE_GET_FREE_SIZE,
SIMCALL_STORAGE_GET_USED_SIZE,
SIMCALL_STORAGE_GET_PROPERTIES,
static inline void simcall_file_get_info__set__result(smx_simcall_t simcall, void* result){
simcall->result.dp = result;
}
-
-
+static inline int simcall_file_move__get__result(smx_simcall_t simcall){
+ return simcall->result.i;
+}
+static inline void simcall_file_move__set__result(smx_simcall_t simcall, int result){
+ simcall->result.i = result;
+}
static inline sg_size_t simcall_storage_get_free_size__get__result(smx_simcall_t simcall){
return simcall->result.sgsz;
}
[SIMCALL_FILE_TELL] = "SIMCALL_FILE_TELL",
[SIMCALL_FILE_SEEK] = "SIMCALL_FILE_SEEK",
[SIMCALL_FILE_GET_INFO] = "SIMCALL_FILE_GET_INFO",
-[SIMCALL_STORAGE_FILE_RENAME] = "SIMCALL_STORAGE_FILE_RENAME",
+[SIMCALL_FILE_MOVE] = "SIMCALL_FILE_MOVE",
[SIMCALL_STORAGE_GET_FREE_SIZE] = "SIMCALL_STORAGE_GET_FREE_SIZE",
[SIMCALL_STORAGE_GET_USED_SIZE] = "SIMCALL_STORAGE_GET_USED_SIZE",
[SIMCALL_STORAGE_GET_PROPERTIES] = "SIMCALL_STORAGE_GET_PROPERTIES",
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)
+int SIMIX_pre_file_move(smx_simcall_t simcall, smx_file_t file, const char* fullpath)
{
- return SIMIX_storage_file_rename(simcall->issuer, storage, src, dest);
+ return SIMIX_file_move(simcall->issuer, file, fullpath);
}
-void SIMIX_storage_file_rename(smx_process_t process, smx_storage_t storage, const char* src, const char* dest)
+int SIMIX_file_move(smx_process_t process, smx_file_t file, const char* fullpath)
{
- return surf_storage_rename(storage, src, dest);
+ smx_host_t host = process->smx_host;
+ return surf_workstation_file_move(host, file->surf_file, fullpath);
}
sg_size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall, const char* name)
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);
-
+int SIMIX_pre_file_move(smx_simcall_t simcall, smx_file_t fd, const char* fullpath);
smx_action_t SIMIX_file_read(smx_process_t process, smx_file_t fd, sg_size_t size);
smx_action_t SIMIX_file_write(smx_process_t process, smx_file_t fd, sg_size_t size);
smx_action_t SIMIX_file_open(smx_process_t process, const char* fullpath);
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);
int SIMIX_file_seek(smx_process_t process, smx_file_t fd, sg_size_t offset, int origin);
+int SIMIX_file_move(smx_process_t process, smx_file_t fd, const char* fullpath);
-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);
/**
* \ingroup simix_file_management
+ * \brief Move a file to another location on the *same mount point*.
*
*/
-void simcall_storage_file_rename(smx_storage_t storage, const char* src, const char* dest)
+int simcall_file_move(smx_file_t fd, const char* fullpath)
{
- return simcall_BODY_storage_file_rename(storage, src, dest);
+ return simcall_BODY_file_move(fd, fullpath);
}
/**
*/
virtual StorageActionPtr write(surf_file_t fd, sg_size_t size)=0;
- /**
- * @brief Rename a path
- *
- * @param src The old path
- * @param dest The new path
- */
- virtual void rename(const char *src, const char *dest)=0;
-
/**
* @brief Get the content of the current Storage
*
return action;
}
-void StorageN11::rename(const char *src, const char *dest)
-{
- sg_size_t *psize, *new_psize;
- psize = (sg_size_t*) xbt_dict_get_or_null(p_content,src);
- new_psize = xbt_new(sg_size_t, 1);
- *new_psize = *psize;
- if (psize){// src file exists
- xbt_dict_remove(p_content, src);
- xbt_dict_set(p_content, dest, new_psize,NULL);
- XBT_DEBUG("Change file name from %s to %s, size '%llu'",src, dest, *psize);
- }
- else
- XBT_DEBUG("File %s doesn't exist",src);
-}
-
/**********
* Action *
**********/
return get_casted_workstation(workstation)->fileSeek(fd, offset, origin);
}
+int surf_workstation_file_move(surf_resource_t workstation, surf_file_t fd, const char* fullpath){
+ return get_casted_workstation(workstation)->fileMove(fd, fullpath);
+}
+
xbt_dynar_t surf_workstation_get_vms(surf_resource_t resource){
return get_casted_workstation(resource)->getVms();
}
return static_cast<StoragePtr>(surf_storage_resource_priv(resource))->p_attach;
}
-void surf_storage_rename(surf_resource_t resource, const char* src, const char* dest){
- static_cast<StoragePtr>(surf_storage_resource_priv(resource))->rename(src, dest);
-}
-
surf_action_t surf_cpu_execute(surf_resource_t cpu, double size){
return get_casted_cpu(cpu)->execute(size);
}
}
}
+int Workstation::fileMove(surf_file_t fd, const char* fullpath){
+
+ /* Check if the new full path is on the same mount point */
+ if(!strncmp((const char*)fd->mount, fullpath, strlen(fd->mount)))
+ {
+ sg_size_t *psize, *new_psize;
+ psize = (sg_size_t*) xbt_dict_get_or_null(findStorageOnMountList(fd->mount)->p_content,fd->name);
+ new_psize = xbt_new(sg_size_t, 1);
+ *new_psize = *psize;
+ if (psize){// src file exists
+ xbt_dict_remove(findStorageOnMountList(fd->mount)->p_content, fd->name);
+
+ char *path = (char *) xbt_malloc ((strlen(fullpath)-strlen(fd->mount)+1));;
+ strncpy(path, fullpath+strlen(fd->mount), strlen(fullpath)-strlen(fd->mount)+1);
+ xbt_dict_set(findStorageOnMountList(fd->mount)->p_content, path, new_psize,NULL);
+ XBT_DEBUG("Move file from %s to %s, size '%llu'",fd->name, fullpath, *psize);
+ free(path);
+ return MSG_OK;
+ }
+ else
+ XBT_WARN("File %s doesn't exist", fd->name);
+ return MSG_TASK_CANCELED;
+ }
+ else
+ {
+ XBT_WARN("New full path %s is not on the same mount point: %s. Action has been canceled.", fullpath, fd->mount);
+ return MSG_TASK_CANCELED;
+ }
+}
+
+
sg_size_t Workstation::getFreeSize(const char* name)
{
StoragePtr st = findStorageOnMountList(name);
*/
virtual int fileSeek(surf_file_t fd, sg_size_t offset, int origin);
+ /**
+ * @brief Move a file to another location on the *same mount point*.
+ * @details [long description]
+ *
+ * @param fd The file descriptor
+ * @param fullpath The new full path
+ * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
+ * full path is not on the same mount point
+ */
+ virtual int fileMove(surf_file_t fd, const char* fullpath);
+
xbt_dynar_t p_storage;
RoutingEdgePtr p_netElm;
CpuPtr p_cpu;