XBT_PUBLIC(int) simcall_sem_get_capacity(smx_sem_t sem);
/***************************** File **********************************/
-XBT_PUBLIC(void*) simcall_file_get_data(surf_file_t fd);
-XBT_PUBLIC(void) simcall_file_set_data(surf_file_t fd, void* data);
XBT_PUBLIC(sg_size_t) simcall_file_read(surf_file_t fd, sg_size_t size, sg_host_t host);
XBT_PUBLIC(sg_size_t) simcall_file_write(surf_file_t fd, sg_size_t size, sg_host_t host);
XBT_PUBLIC(surf_file_t) simcall_file_open(const char* mount, const char* path, sg_storage_t st);
XBT_PUBLIC(int) simcall_file_close(surf_file_t fd, sg_host_t host);
-XBT_PUBLIC(int) simcall_file_unlink(surf_file_t fd, sg_host_t host);
-XBT_PUBLIC(sg_size_t) simcall_file_get_size(surf_file_t fd);
-XBT_PUBLIC(sg_size_t) simcall_file_tell(surf_file_t fd);
-XBT_PUBLIC(int) simcall_file_seek(surf_file_t fd, sg_offset_t offset, int origin);
-XBT_PUBLIC(int) simcall_file_move(surf_file_t fd, const char* fullpath);
/************************** MC simcalls **********************************/
XBT_PUBLIC(int) simcall_mc_random(int min, int max);
void File::move(const char* fullpath)
{
- simcall_file_move(pimpl_,fullpath);
+ sg_host_t host = Host::current();
+ simgrid::simix::kernelImmediate([this, host, fullpath] { pimpl_->move(host, fullpath); });
}
int File::unlink()
{
- return simgrid::simix::kernelImmediate([this] { return pimpl_->unlink(Host::current()); });
+ return unlink(Host::current());
}
int File::unlink(sg_host_t host)
return simcall_BODY_file_close(fd, host);
}
-/**
- * \ingroup simix_file_management
- * \brief Move a file to another location on the *same mount point*.
- *
- */
-int simcall_file_move(surf_file_t fd, const char* fullpath)
-{
- return simcall_BODY_file_move(fd, fullpath);
-}
-
void simcall_run_kernel(std::function<void()> const& code)
{
simcall_BODY_run_kernel(&code);
simgrid::simix::marshal<int>(simcall->result, result);
}
-static inline surf_file_t simcall_file_move__get__fd(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal<surf_file_t>(simcall->args[0]);
-}
-static inline surf_file_t simcall_file_move__getraw__fd(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal_raw<surf_file_t>(simcall->args[0]);
-}
-static inline void simcall_file_move__set__fd(smx_simcall_t simcall, surf_file_t arg)
-{
- simgrid::simix::marshal<surf_file_t>(simcall->args[0], arg);
-}
-static inline const char* simcall_file_move__get__fullpath(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal<const char*>(simcall->args[1]);
-}
-static inline const char* simcall_file_move__getraw__fullpath(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal_raw<const char*>(simcall->args[1]);
-}
-static inline void simcall_file_move__set__fullpath(smx_simcall_t simcall, const char* arg)
-{
- simgrid::simix::marshal<const char*>(simcall->args[1], arg);
-}
-static inline int simcall_file_move__get__result(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal<int>(simcall->result);
-}
-static inline int simcall_file_move__getraw__result(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal_raw<int>(simcall->result);
-}
-static inline void simcall_file_move__set__result(smx_simcall_t simcall, int result){
- simgrid::simix::marshal<int>(simcall->result, result);
-}
-
static inline int simcall_mc_random__get__min(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal<int>(simcall->args[0]);
XBT_PRIVATE void simcall_HANDLER_file_write(smx_simcall_t simcall, surf_file_t fd, sg_size_t size, sg_host_t host);
XBT_PRIVATE void simcall_HANDLER_file_open(smx_simcall_t simcall, const char* mount, const char* path, sg_storage_t st);
XBT_PRIVATE void simcall_HANDLER_file_close(smx_simcall_t simcall, surf_file_t fd, sg_host_t host);
-XBT_PRIVATE int simcall_HANDLER_file_move(smx_simcall_t simcall, surf_file_t fd, const char* fullpath);
XBT_PRIVATE int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max);
\ No newline at end of file
return simcall<int, surf_file_t, sg_host_t>(SIMCALL_FILE_CLOSE, fd, host);
}
- inline static int simcall_BODY_file_move(surf_file_t fd, const char* fullpath)
- {
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) simcall_HANDLER_file_move(&SIMIX_process_self()->simcall, fd, fullpath);
- return simcall<int, surf_file_t, const char*>(SIMCALL_FILE_MOVE, fd, fullpath);
- }
-
inline static int simcall_BODY_mc_random(int min, int max) {
/* Go to that function to follow the code flow through the simcall barrier */
if (0) simcall_HANDLER_mc_random(&SIMIX_process_self()->simcall, min, max);
SIMCALL_FILE_WRITE,
SIMCALL_FILE_OPEN,
SIMCALL_FILE_CLOSE,
- SIMCALL_FILE_MOVE,
SIMCALL_MC_RANDOM,
SIMCALL_SET_CATEGORY,
SIMCALL_RUN_KERNEL,
"SIMCALL_FILE_WRITE",
"SIMCALL_FILE_OPEN",
"SIMCALL_FILE_CLOSE",
- "SIMCALL_FILE_MOVE",
"SIMCALL_MC_RANDOM",
"SIMCALL_SET_CATEGORY",
"SIMCALL_RUN_KERNEL",
simgrid::simix::unmarshal<sg_host_t>(simcall->args[1]));
break;
-case SIMCALL_FILE_MOVE:
- simgrid::simix::marshal<int>(
- simcall->result, simcall_HANDLER_file_move(simcall, simgrid::simix::unmarshal<surf_file_t>(simcall->args[0]),
- simgrid::simix::unmarshal<const char*>(simcall->args[1])));
- SIMIX_simcall_answer(simcall);
- break;
-
case SIMCALL_MC_RANDOM:
simgrid::simix::marshal<int>(simcall->result, simcall_HANDLER_mc_random(simcall, simgrid::simix::unmarshal<int>(simcall->args[0]), simgrid::simix::unmarshal<int>(simcall->args[1])));
SIMIX_simcall_answer(simcall);
sg_size_t file_write(surf_file_t fd, sg_size_t size, sg_host_t host) [[block]];
surf_file_t file_open(const char* mount, const char* path, sg_storage_t st) [[block]];
int file_close(surf_file_t fd, sg_host_t host) [[block]];
-int file_move(surf_file_t fd, const char* fullpath);
int mc_random(int min, int max);
void set_category(boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> synchro, const char* category) [[nohandler]];
return synchro;
}
-int simcall_HANDLER_file_move(smx_simcall_t simcall, surf_file_t file, const char* fullpath)
-{
- return SIMIX_file_move(simcall->issuer, file, fullpath);
-}
-
-int SIMIX_file_move(smx_actor_t process, surf_file_t file, const char* fullpath)
-{
- sg_host_t host = process->host;
- return surf_host_file_move(host, file, fullpath);
-}
-
void SIMIX_io_destroy(smx_activity_t synchro)
{
simgrid::kernel::activity::IoImplPtr io = boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(synchro);
return 0;
}
}
+
+void FileImpl::move(sg_host_t host, const char* fullpath)
+{
+ /* Check if the new full path is on the same mount point */
+ if (not strncmp(mount_point_.c_str(), fullpath, mount_point_.size())) {
+ std::map<std::string, sg_size_t>* content = host->pimpl_->findStorageOnMountList(mount_point_.c_str())->content_;
+ if (content->find(path_) != content->end()) { // src file exists
+ sg_size_t new_size = content->at(path_);
+ content->erase(path_);
+ std::string path = std::string(fullpath).substr(mount_point_.size(), strlen(fullpath));
+ content->insert({path.c_str(), new_size});
+ XBT_DEBUG("Move file from %s to %s, size '%llu'", path_.c_str(), fullpath, new_size);
+ } else {
+ XBT_WARN("File %s doesn't exist", path_.c_str());
+ }
+ } else {
+ XBT_WARN("New full path %s is not on the same mount point: %s.", fullpath, mount_point_.c_str());
+ }
+}
}
}
sg_size_t tell() { return current_position_; }
int seek(sg_offset_t offset, int origin);
int unlink(sg_host_t host);
+ void move(sg_host_t host, const char* fullpath);
private:
std::string path_;
return st->write(fd, size);
}
-int HostImpl::fileMove(surf_file_t fd, const char* fullpath)
-{
- /* Check if the new full path is on the same mount point */
- if (not strncmp(fd->mount(), fullpath, strlen(fd->mount()))) {
- std::map<std::string, sg_size_t>* content = findStorageOnMountList(fd->mount())->content_;
- if (content->find(fd->name()) != content->end()) { // src file exists
- sg_size_t new_size = content->at(fd->name());
- content->erase(fd->name());
- std::string path = std::string(fullpath).substr(strlen(fd->mount()), strlen(fullpath));
- content->insert({path.c_str(), new_size});
- XBT_DEBUG("Move file from %s to %s, size '%llu'", fd->cname(), fullpath, new_size);
- return 0;
- } else {
- XBT_WARN("File %s doesn't exist", fd->cname());
- return -1;
- }
- } else {
- XBT_WARN("New full path %s is not on the same mount point: %s. Action has been canceled.", fullpath, fd->mount());
- return -1;
- }
-}
-
}
}
*/
virtual Action* write(surf_file_t fd, sg_size_t size);
- /**
- * @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);
-
std::map<std::string, simgrid::surf::StorageImpl*> storage_;
simgrid::s4u::Host* piface_ = nullptr;
return host->pimpl_->write(fd, size);
}
-int surf_host_file_move(sg_host_t host, surf_file_t fd, const char* fullpath){
- return host->pimpl_->fileMove(fd, fullpath);
-}
-
void surf_cpu_action_set_bound(surf_action_t action, double bound) {
static_cast<simgrid::surf::CpuAction*>(action)->setBound(bound);
}