SimGrid (3.18) NOT RELEASED YET (target: December 24 2017)
S4U
- - Link::name() is deprecated and will be removed in v3.21, use instead
- Link::getCname().
- - Mailbox::getName() changed to return a std::string, use instead
- Mailbox::getCname() to get a char*.
- - Storage::getName() changed to return a std::string, use intead
- Storage::getCname() to get a char*.
+ - Link::name() is deprecated and will be removed in v3.21, use
+ Link::getCname() instead.
+ - Mailbox::getName() changed to return a std::string, use
+ Mailbox::getCname() instead to get a char*.
+ - Storage::getName() changed to return a std::string, use
+ Storage::getCname() instead to get a char*.
MSG
- Deprecate MSG_task_get_flops_amount(). Its semantic was weird:
PLUGINS:
- New link_energy plugin for the consumption of the links.
+ - Most of the operations on files and storage contents have been
+ packaged into a plugin (src/plugins/file_system). The current
+ public interface can be found in
+ include/simgrid/plugins/file_system.h
+ To use these functions you now have to initialize the plugin by
+ calling MSG_storage_file_system_init() just after calling
+ MSG_init() or sg_storage_file_system_init() just after creating
+ the Engine.
XML
- Remove the undocumented/untested tag <include>
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/msg.h"
-#include "simgrid/plugins/file_system.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
XBT_PUBLIC(sg_size_t) MSG_file_read(msg_file_t fd, sg_size_t size);
XBT_PUBLIC(sg_size_t) MSG_file_write(msg_file_t fd, sg_size_t size);
XBT_PUBLIC(msg_file_t) MSG_file_open(const char* fullpath, void* data);
-XBT_PUBLIC(void*) MSG_file_get_data(msg_file_t fd);
-XBT_PUBLIC(msg_error_t) MSG_file_set_data(msg_file_t fd, void * data);
XBT_PUBLIC(int) MSG_file_close(msg_file_t fd);
-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(msg_error_t) MSG_file_unlink(msg_file_t fd);
-XBT_PUBLIC(msg_error_t) MSG_file_seek(msg_file_t fd, sg_offset_t offset, int origin);
-XBT_PUBLIC(sg_size_t) MSG_file_tell (msg_file_t fd);
-XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t file);
XBT_PUBLIC(msg_error_t) MSG_file_move(msg_file_t fd, const char* fullpath);
XBT_PUBLIC(msg_error_t) MSG_file_rcopy(msg_file_t fd, msg_host_t host, const char* fullpath);
XBT_PUBLIC(msg_error_t) MSG_file_rmove(msg_file_t fd, msg_host_t host, const char* fullpath);
XBT_PUBLIC(xbt_dynar_t) MSG_storages_as_dynar();
XBT_PUBLIC(msg_error_t) MSG_storage_set_data(msg_storage_t host, void *data);
XBT_PUBLIC(void *) MSG_storage_get_data(msg_storage_t storage);
-XBT_PUBLIC(xbt_dict_t) MSG_storage_get_content(msg_storage_t storage);
XBT_PUBLIC(const char *) MSG_storage_get_host(msg_storage_t storage);
XBT_PUBLIC(sg_size_t) MSG_storage_read(msg_storage_t storage, sg_size_t size);
XBT_PUBLIC(sg_size_t) MSG_storage_write(msg_storage_t storage, sg_size_t size);
XBT_PUBLIC(int) MSG_get_host_number();
XBT_PUBLIC(xbt_dict_t) MSG_host_get_mounted_storage_list(msg_host_t host);
XBT_PUBLIC(xbt_dynar_t) MSG_host_get_attached_storage_list(msg_host_t host);
-XBT_PUBLIC(xbt_dict_t) MSG_host_get_storage_content(msg_host_t host);
/*property handlers*/
XBT_PUBLIC(xbt_dict_t) MSG_host_get_properties(msg_host_t host);
-XBT_PUBLIC(const char *) MSG_host_get_property_value(msg_host_t host,
- const char *name);
+XBT_PUBLIC(const char*) MSG_host_get_property_value(msg_host_t host, const char* name);
XBT_PUBLIC(void) MSG_host_set_property_value(msg_host_t host, const char* name, char* value);
XBT_PUBLIC(void) MSG_create_environment(const char *file);
/*property handlers*/
XBT_PUBLIC(xbt_dict_t) MSG_process_get_properties(msg_process_t process);
-XBT_PUBLIC(const char *) MSG_process_get_property_value(msg_process_t
- process,
- const char *name);
+XBT_PUBLIC(const char*) MSG_process_get_property_value(msg_process_t process, const char* name);
XBT_PUBLIC(msg_error_t) MSG_process_suspend(msg_process_t process);
XBT_PUBLIC(msg_error_t) MSG_process_resume(msg_process_t process);
XBT_PUBLIC(void) MSG_process_unref(msg_process_t process);
/************************** Task handling ************************************/
-XBT_PUBLIC(msg_task_t) MSG_task_create(const char *name,
- double flops_amount,
- double bytes_amount, void *data);
+XBT_PUBLIC(msg_task_t) MSG_task_create(const char* name, double flops_amount, double bytes_amount, void* data);
XBT_PUBLIC(msg_task_t) MSG_parallel_task_create(const char *name,
int host_nb,
const msg_host_t * host_list,
SG_BEGIN_DECL()
XBT_PUBLIC(void) sg_storage_file_system_init();
+
+XBT_PUBLIC(const char*) sg_file_get_name(sg_file_t fd);
+XBT_PUBLIC(sg_size_t) sg_file_get_size(sg_file_t fd);
+XBT_PUBLIC(void) sg_file_dump(sg_file_t fd);
+XBT_PUBLIC(void*) sg_file_get_data(sg_file_t fd);
+XBT_PUBLIC(void) sg_file_set_data(sg_file_t fd, void* data);
+XBT_PUBLIC(void) sg_file_seek(sg_file_t fd, sg_offset_t offset, int origin);
+XBT_PUBLIC(sg_size_t) sg_file_tell(sg_file_t fd);
+XBT_PUBLIC(void) sg_file_move(sg_file_t fd, const char* fullpath);
+XBT_PUBLIC(void) sg_file_unlink(sg_file_t fd);
+
+XBT_PUBLIC(void*) sg_storage_get_data(sg_storage_t storage);
+XBT_PUBLIC(void) sg_storage_set_data(sg_storage_t storage, void* data);
XBT_PUBLIC(sg_size_t) sg_storage_get_size_free(sg_storage_t st);
XBT_PUBLIC(sg_size_t) sg_storage_get_size_used(sg_storage_t st);
XBT_PUBLIC(sg_size_t) sg_storage_get_size(sg_storage_t st);
+XBT_PUBLIC(xbt_dict_t) sg_storage_get_content(sg_storage_t storage);
+
+XBT_PUBLIC(xbt_dict_t) sg_host_get_storage_content(sg_host_t host);
+
+#define MSG_file_get_name(fd) sg_file_get_name(fd)
+#define MSG_file_get_size(fd) sg_file_get_size(fd)
+#define MSG_file_dump(fd) sg_file_dump(fd)
+#define MSG_file_get_data(fd) sg_file_get_data(fd)
+#define MSG_file_set_data(fd, data) sg_file_set_data(fd, data)
+#define MSG_file_seek(fd, offset, origin) sg_file_seek(fd, offset, origin)
+#define MSG_file_tell(fd) sg_file_tell(fd)
+#define MSG_file_move(fd, fullpath) sg_file_get_size(fd, fullpath)
+#define MSG_file_unlink(fd) sg_file_unlink(fd)
#define MSG_storage_file_system_init() sg_storage_file_system_init()
#define MSG_storage_get_free_size(st) sg_storage_get_size_free(st)
#define MSG_storage_get_used_size(st) sg_storage_get_size_used(st)
#define MSG_storage_get_size(st) sg_storage_get_size(st)
+#define MSG_storage_get_content(st) sg_storage_get_content(st)
+
+#define MSG_host_get_storage_content(st) sg_host_get_storage_content(st)
SG_END_DECL()
#ifndef MSG_JFILE_H
#define MSG_JFILE_H
-#include <jni.h>
#include "simgrid/msg.h"
+#include "simgrid/plugins/file_system.h"
+#include <jni.h>
SG_BEGIN_DECL()
#ifndef MSG_JHOST_H
#define MSG_JHOST_H
-#include <jni.h>
#include "simgrid/msg.h"
+#include "simgrid/plugins/file_system.h"
+#include <jni.h>
SG_BEGIN_DECL()
return sg_host_get_attached_storage_list(host);
}
-/** \ingroup m_host_management
- * \brief Return the content of mounted storages on an host.
- * \param host a host
- * \return a dict containing content (as a dict) of all storages mounted on the host
- */
-xbt_dict_t MSG_host_get_storage_content(msg_host_t host)
-{
- xbt_assert((host != nullptr), "Invalid parameters");
- xbt_dict_t contents = xbt_dict_new_homogeneous(nullptr);
- for (auto const& elm : host->getMountedStorages())
- xbt_dict_set(contents, elm.first.c_str(), MSG_storage_get_content(elm.second), nullptr);
-
- return contents;
-}
}
host->extension<simgrid::MsgHostExt>()->file_descriptor_table->push_back(id);
}
-/** \ingroup msg_file
- *
- * \brief Set the user data of a #msg_file_t.
- *
- * This functions attach \a data to \a file.
- */
-msg_error_t MSG_file_set_data(msg_file_t fd, void *data)
-{
- fd->setUserdata(data);
- return MSG_OK;
-}
-
-/** \ingroup msg_file
- *
- * \brief Return the user data of a #msg_file_t.
- *
- * This functions checks whether \a file is a valid pointer and return the user data associated to \a file if possible.
- */
-void* MSG_file_get_data(msg_file_t fd)
-{
- return fd->getUserdata();
-}
-
-/** \ingroup msg_file
- * \brief Display information related to a file descriptor
- *
- * \param fd is a the file descriptor
- */
-void MSG_file_dump (msg_file_t fd){
- XBT_INFO("File Descriptor information:\n"
- "\t\tFull path: '%s'\n"
- "\t\tSize: %llu\n"
- "\t\tMount point: '%s'\n"
- "\t\tStorage Id: '%s'\n"
- "\t\tStorage Type: '%s'\n"
- "\t\tFile Descriptor Id: %d",
- fd->getPath(), fd->size(), fd->mount_point_.c_str(), fd->localStorage->getCname(),
- fd->localStorage->getType(), fd->desc_id);
-}
-
/** \ingroup msg_file
* \brief Read a file (local or remote)
*
return MSG_OK;
}
-/** \ingroup msg_file
- * \brief Unlink the file pointed by fd
- *
- * \param fd is the file descriptor (#msg_file_t)
- * \return 0 on success or 1 on error
- */
-msg_error_t MSG_file_unlink(msg_file_t fd)
-{
- fd->unlink();
- delete fd;
- return MSG_OK;
-}
-
-/** \ingroup msg_file
- * \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)
- */
-sg_size_t MSG_file_get_size(msg_file_t fd)
-{
- return fd->size();
-}
-
-/**
- * \ingroup msg_file
- * \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 \<stdio.h\> 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_offset_t offset, int origin)
-{
- fd->seek(offset, origin);
- return MSG_OK;
-}
-
-/**
- * \ingroup msg_file
- * \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 fd->tell();
-}
-
-const char *MSG_file_get_name(msg_file_t fd) {
- xbt_assert((fd != nullptr), "Invalid parameters");
- return fd->getPath();
-}
-
-/**
- * \ingroup msg_file
- * \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)
-{
- fd->move(fullpath);
- return MSG_OK;
-}
-
/**
* \ingroup msg_file
* \brief Copy a file to another location on a remote host.
return storage->getCname();
}
+const char* MSG_storage_get_host(msg_storage_t storage)
+{
+ xbt_assert((storage != nullptr), "Invalid parameters");
+ return storage->getHost()->getCname();
+}
+
/** \ingroup msg_storage_management
* \brief Returns a xbt_dict_t consisting of the list of properties assigned to this storage
* \param storage a storage
return res;
}
-/** \ingroup msg_storage_management
- *
- * \brief Set the user data of a #msg_storage_t.
- * This functions attach \a data to \a storage if possible.
- */
-msg_error_t MSG_storage_set_data(msg_storage_t storage, void *data)
-{
- storage->setUserdata(data);
- return MSG_OK;
-}
-
-/** \ingroup m_host_management
- *
- * \brief Returns the user data of a #msg_storage_t.
- *
- * This functions checks whether \a storage is a valid pointer and returns its associate user data if possible.
- */
-void *MSG_storage_get_data(msg_storage_t storage)
+void* MSG_storage_get_data(msg_storage_t storage)
{
xbt_assert((storage != nullptr), "Invalid parameters");
return storage->getUserdata();
}
-/** \ingroup msg_storage_management
- *
- * \brief Returns the content (file list) of a #msg_storage_t.
- * \param storage a storage
- * \return The content of this storage element as a dict (full path file => size)
- */
-xbt_dict_t MSG_storage_get_content(msg_storage_t storage)
-{
- std::map<std::string, sg_size_t>* content = storage->extension<simgrid::s4u::FileSystemStorageExt>()->getContent();
- // Note: ::operator delete is ok here (no destructor called) since the dict elements are of POD type sg_size_t.
- xbt_dict_t content_as_dict = xbt_dict_new_homogeneous(::operator delete);
-
- for (auto const& entry : *content) {
- sg_size_t* psize = new sg_size_t;
- *psize = entry.second;
- xbt_dict_set(content_as_dict, entry.first.c_str(), psize, nullptr);
- }
- return content_as_dict;
-}
-
-/** \ingroup msg_storage_management
- *
- * \brief Returns the host name the storage is attached to
- *
- * This functions checks whether a storage is a valid pointer or not and return its name.
- */
-const char* MSG_storage_get_host(msg_storage_t storage)
+msg_error_t MSG_storage_set_data(msg_storage_t storage, void *data)
{
- xbt_assert((storage != nullptr), "Invalid parameters");
- return storage->getHost()->getCname();
+ storage->setUserdata(data);
+ return MSG_OK;
}
sg_size_t MSG_storage_read(msg_storage_t storage, sg_size_t size)
{
return storage->write(size);
}
+
}
/** Retrieves the previously stored data */
void* getUserdata() { return userdata_; }
- /** Retrieve the datasize */
sg_size_t size();
-
- /** Sets the file head to the given position. */
- void seek(sg_offset_t pos);
- void seek(sg_offset_t pos, int origin);
-
- /** Retrieves the current file position */
- sg_size_t tell();
+ void seek(sg_offset_t pos); /** Sets the file head to the given position. */
+ void seek(sg_offset_t pos, int origin); /** Sets the file head to the given position from a given origin. */
+ sg_size_t tell(); /** Retrieves the current file position */
/** Rename a file. WARNING: It is forbidden to move the file to another mount point */
void move(std::string fullpath);
- /** Remove a file from disk */
- int unlink();
+ int unlink(); /** Remove a file from the contents of a disk */
+ void dump();
int desc_id = 0;
Storage* localStorage;
}
}
+void File::dump()
+{
+ XBT_INFO("File Descriptor information:\n"
+ "\t\tFull path: '%s'\n"
+ "\t\tSize: %llu\n"
+ "\t\tMount point: '%s'\n"
+ "\t\tStorage Id: '%s'\n"
+ "\t\tStorage Type: '%s'\n"
+ "\t\tFile Descriptor Id: %d",
+ getPath(), size_, mount_point_.c_str(), localStorage->getCname(), localStorage->getType(), desc_id);
+}
+
sg_size_t File::read(sg_size_t size)
{
XBT_DEBUG("READ %s on disk '%s'", getPath(), localStorage->getCname());
void sg_storage_file_system_init()
{
-
if (FileSystemStorageExt::EXTENSION_ID.valid())
return;
simgrid::s4u::Storage::onDestruction.connect(&onStorageDestruction);
}
+const char* sg_file_get_name(sg_file_t fd)
+{
+ xbt_assert((fd != nullptr), "Invalid file descriptor");
+ return fd->getPath();
+}
+
+sg_size_t sg_file_get_size(sg_file_t fd)
+{
+ return fd->size();
+}
+
+void sg_file_dump(sg_file_t fd)
+{
+ fd->dump();
+}
+
+void* sg_file_get_data(sg_file_t fd)
+{
+ return fd->getUserdata();
+}
+
+void sg_file_set_data(sg_file_t fd, void* data)
+{
+ fd->setUserdata(data);
+}
+
+/**
+ * \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 \<stdio.h\> 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)
+ */
+void sg_file_seek(sg_file_t fd, sg_offset_t offset, int origin)
+{
+ fd->seek(offset, origin);
+}
+
+sg_size_t sg_file_tell(sg_file_t fd)
+{
+ return fd->tell();
+}
+
+void sg_file_move(sg_file_t fd, const char* fullpath)
+{
+ fd->move(fullpath);
+}
+
+void sg_file_unlink(sg_file_t fd)
+{
+ fd->unlink();
+ delete fd;
+}
+
sg_size_t sg_storage_get_size_free(sg_storage_t st)
{
return st->extension<FileSystemStorageExt>()->getSize() - st->extension<FileSystemStorageExt>()->getUsedSize();
return st->extension<FileSystemStorageExt>()->getSize();
}
+xbt_dict_t sg_storage_get_content(sg_storage_t storage)
+{
+ std::map<std::string, sg_size_t>* content = storage->extension<simgrid::s4u::FileSystemStorageExt>()->getContent();
+ // Note: ::operator delete is ok here (no destructor called) since the dict elements are of POD type sg_size_t.
+ xbt_dict_t content_as_dict = xbt_dict_new_homogeneous(::operator delete);
+
+ for (auto const& entry : *content) {
+ sg_size_t* psize = new sg_size_t;
+ *psize = entry.second;
+ xbt_dict_set(content_as_dict, entry.first.c_str(), psize, nullptr);
+ }
+ return content_as_dict;
+}
+
+xbt_dict_t sg_host_get_storage_content(sg_host_t host)
+{
+ xbt_assert((host != nullptr), "Invalid parameters");
+ xbt_dict_t contents = xbt_dict_new_homogeneous(nullptr);
+ for (auto const& elm : host->getMountedStorages())
+ xbt_dict_set(contents, elm.first.c_str(), sg_storage_get_content(elm.second), nullptr);
+
+ return contents;
+}
+
SG_END_DECL()