From 014c2c9d0ef618af3f9412c657e46f51e2ef22b0 Mon Sep 17 00:00:00 2001 From: Henri Casanova Date: Fri, 11 Oct 2024 09:14:55 -1000 Subject: [PATCH] Code re-organization Documentation fixes (more to go later) --- conf/doxygen/Doxyfile.in | 4 +-- include/fsmod/File.hpp | 19 +++++--------- include/fsmod/FileStat.hpp | 2 +- include/fsmod/FileSystem.hpp | 12 ++------- include/fsmod/JBODStorage.hpp | 7 ++---- include/fsmod/Partition.hpp | 39 +++++----------------------- src/File.cpp | 46 ++++++++++++++++++++++++++++++++++ src/FileSystem.cpp | 16 +++++++++++- src/JBODStorage.cpp | 14 ++++++++++- src/Partition.cpp | 45 +++++++++++++++++++++++++++++++++ test/file_system_test.cpp | 3 +++ test/one_disk_storage_test.cpp | 2 +- 12 files changed, 142 insertions(+), 67 deletions(-) diff --git a/conf/doxygen/Doxyfile.in b/conf/doxygen/Doxyfile.in index efef9f5..26b6363 100644 --- a/conf/doxygen/Doxyfile.in +++ b/conf/doxygen/Doxyfile.in @@ -459,7 +459,7 @@ INLINE_GROUPED_CLASSES = NO # Man pages) or section (for LaTeX and RTF). # The default value is: NO. -INLINE_SIMPLE_STRUCTS = NO +INLINE_SIMPLE_STRUCTS = YES # When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or # enum is documented as struct, union, or enum with the name of the typedef. So @@ -674,7 +674,7 @@ FORCE_LOCAL_INCLUDES = NO # documentation for inline members. # The default value is: YES. -INLINE_INFO = YES +INLINE_INFO = NO # If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the # (detailed) documentation of file and class members alphabetically by member diff --git a/include/fsmod/File.hpp b/include/fsmod/File.hpp index ef0ca18..fe1247c 100644 --- a/include/fsmod/File.hpp +++ b/include/fsmod/File.hpp @@ -44,13 +44,11 @@ namespace simgrid::fsmod { File& operator=(const File&) = delete; virtual ~File() = default; - /** Get the number of bytes actually read by a given I/O Read activity */ - sg_size_t get_num_bytes_read(const s4u::IoPtr& read) const { return read->get_performed_ioops(); } + static sg_size_t get_num_bytes_read(const s4u::IoPtr& read); + static sg_size_t get_num_bytes_written(const s4u::IoPtr& write); - /** Get the number of bytes actually written by a given I/O Write activity */ - sg_size_t get_num_bytes_written(const s4u::IoPtr& write) const { return write->get_performed_ioops(); } - const std::string& get_access_mode() const { return access_mode_; } - const std::string& get_path() const { return path_; } + [[nodiscard]] const std::string& get_access_mode() const; + [[nodiscard]] const std::string& get_path() const; s4u::IoPtr read_async(const std::string& num_bytes); s4u::IoPtr read_async(sg_size_t num_bytes); @@ -63,14 +61,9 @@ namespace simgrid::fsmod { void close() const; - /** - * @brief Retrieve the file system that holds this file - * @return A pointer to a FileSystem - */ - [[nodiscard]] FileSystem *get_file_system() { return partition_->file_system_; } + [[nodiscard]] FileSystem *get_file_system() const; - void seek(sg_offset_t pos, int origin = SEEK_SET); /** Sets the file head to the given position from a given origin. */ - /** Retrieves the current file position */ + void seek(sg_offset_t pos, int origin = SEEK_SET); [[nodiscard]] sg_size_t tell() const { return current_position_; } [[nodiscard]] std::unique_ptr stat() const; diff --git a/include/fsmod/FileStat.hpp b/include/fsmod/FileStat.hpp index e96ed7c..4644b51 100644 --- a/include/fsmod/FileStat.hpp +++ b/include/fsmod/FileStat.hpp @@ -13,7 +13,7 @@ namespace simgrid::fsmod { /** - * @brief A class that implemented a file stat data structure + * @brief A class that implements a file stat data structure */ struct XBT_PUBLIC FileStat { public: diff --git a/include/fsmod/FileSystem.hpp b/include/fsmod/FileSystem.hpp index 68b6397..6dfbf87 100644 --- a/include/fsmod/FileSystem.hpp +++ b/include/fsmod/FileSystem.hpp @@ -49,16 +49,8 @@ namespace simgrid::fsmod { get_file_systems_by_netzone(const s4u::NetZone* netzone); static void register_file_system(const s4u::NetZone* netzone, const std::shared_ptr& fs); - /** - * @brief Retrieves the file system's name - * @return a name - */ - [[nodiscard]] const std::string& get_name() const { return name_; } - /** - * @brief Retrieves the file system's name as a C-style string - * @return a name - */ - [[nodiscard]] const char* get_cname() const { return name_.c_str(); } + [[nodiscard]] const std::string& get_name() const; + [[nodiscard]] const char* get_cname() const; void mount_partition(const std::string &mount_point, std::shared_ptr storage, sg_size_t size, Partition::CachingScheme caching_scheme = Partition::CachingScheme::NONE); diff --git a/include/fsmod/JBODStorage.hpp b/include/fsmod/JBODStorage.hpp index ef542d8..dbe665e 100644 --- a/include/fsmod/JBODStorage.hpp +++ b/include/fsmod/JBODStorage.hpp @@ -39,11 +39,8 @@ namespace simgrid::fsmod { const std::vector& disks, JBODStorage::RAID raid_level = RAID::RAID0); ~JBODStorage() override = default; - /** - * @brief Retrieves the storage's RAID level - * @return A RAID level - */ - [[nodiscard]] RAID get_raid_level() const { return raid_level_; } + + [[nodiscard]] RAID get_raid_level() const; void set_raid_level(RAID raid_level); diff --git a/include/fsmod/Partition.hpp b/include/fsmod/Partition.hpp index 445b1a8..a417167 100644 --- a/include/fsmod/Partition.hpp +++ b/include/fsmod/Partition.hpp @@ -22,6 +22,7 @@ namespace simgrid::fsmod { class XBT_PUBLIC Partition { public: + /** * @brief An enum that defines the possible caching schemes that can * be used by a partition @@ -47,39 +48,11 @@ namespace simgrid::fsmod { /** \endcond */ - /** - * @brief Retrieves the partition's name - * @return a name - */ - [[nodiscard]] const std::string& get_name() const { return name_; } - /** - * @brief Retrieves the partition's name as a C-style string - * @return a name - */ - [[nodiscard]] const char* get_cname() const { return name_.c_str(); } - /** - * @brief Retrieves the partition's size in bytes - * @return a number of bytes - */ - [[nodiscard]] sg_size_t get_size() const { return size_; } - - /** - * @brief Retrieves the partition's free space in bytes - * @return a number of bytes - */ - [[nodiscard]] sg_size_t get_free_space() const { return free_space_; } - - /** - * @brief Retrieves the number of files stored in the partition - * @return a number of files - */ - [[nodiscard]] sg_size_t get_num_files() const { - sg_size_t to_return = 0; - for (auto const &[dir_path, files] : content_) { - to_return += files.size(); - } - return to_return; - } + [[nodiscard]] const std::string& get_name() const; + [[nodiscard]] const char* get_cname() const; + [[nodiscard]] sg_size_t get_size() const; + [[nodiscard]] sg_size_t get_free_space() const; + [[nodiscard]] sg_size_t get_num_files() const; protected: friend class FileSystem; diff --git a/src/File.cpp b/src/File.cpp index 3694759..36eeed9 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -145,6 +145,7 @@ namespace simgrid::fsmod { * @brief Write data to the file * @param num_bytes: the number of bytes to write as a string with units * @param simulate_it: if true simulate the I/O, if false the I/O takes zero time + * @return The number of bytes written */ sg_size_t File::write(const std::string& num_bytes, bool simulate_it) { return write(static_cast(xbt_parse_get_size("", 0, num_bytes, "")), simulate_it); @@ -154,6 +155,7 @@ namespace simgrid::fsmod { * @brief Write data to the file * @param num_bytes: the number of bytes to write * @param simulate_it: if true simulate the I/O, if false the I/O takes zero time + * @return The number of bytes written */ sg_size_t File::write(sg_size_t num_bytes, bool simulate_it) { if (num_bytes == 0) /* Nothing to write, return */ @@ -228,4 +230,48 @@ namespace simgrid::fsmod { partition_->file_system_->num_open_files_--; } + + /** + * @brief Get the number of bytes actually read by a given I/O Read activity + * @param write: the I/O (read) activity + * @return a number of bytes + */ + sg_size_t File::get_num_bytes_read(const s4u::IoPtr& read) { + return read->get_performed_ioops(); + } + + /** + * @brief Get the number of bytes actually written by a given I/O Write activity + * @param write: the I/O (write) activity + * @return a number of bytes + */ + sg_size_t File::get_num_bytes_written(const s4u::IoPtr& write) { + return write->get_performed_ioops(); + } + + /** + * @brief Get the file's access mode + * @return an access mode string + */ + const std::string& File::get_access_mode() const { + return access_mode_; + } + + /** + * @brief Get the file's full path + * @return a path string + */ + const std::string& File::get_path() const { + return path_; + } + + /** + * @brief Retrieve the file system that holds this file + * @return A pointer to a FileSystem + */ + FileSystem *File::get_file_system() const { + return partition_->file_system_; + } + + } diff --git a/src/FileSystem.cpp b/src/FileSystem.cpp index fbb8ec4..0e5dcd7 100644 --- a/src/FileSystem.cpp +++ b/src/FileSystem.cpp @@ -464,7 +464,6 @@ namespace simgrid::fsmod { partition->delete_directory(path_at_mount_point); } - /** * @brief Returns the free space on the path's partition * @param full_path: a path @@ -476,5 +475,20 @@ namespace simgrid::fsmod { return partition->get_free_space(); } + /** + * @brief Retrieves the file system's name + * @return a name + */ + const std::string& FileSystem::get_name() const { + return name_; + } + + /** + * @brief Retrieves the file system's name as a C-style string + * @return a name + */ + const char* FileSystem::get_cname() const { + return name_.c_str(); + } } diff --git a/src/JBODStorage.cpp b/src/JBODStorage.cpp index 9d811f0..1423bb0 100644 --- a/src/JBODStorage.cpp +++ b/src/JBODStorage.cpp @@ -38,7 +38,19 @@ namespace simgrid::fsmod { [this]() { get_message_queue()->get(); })->daemonize()); } - void JBODStorage::set_raid_level(RAID raid_level) { + /** + * @brief Retrieve the storage's RAID level + * @return A RAID level + */ + JBODStorage::RAID JBODStorage::get_raid_level() const { + return raid_level_; + } + + /** + * @brief Set the storage's RAID level + * @param raid_level: a RAID level + */ + void JBODStorage::set_raid_level(JBODStorage::RAID raid_level) { if ((raid_level == RAID::RAID4 || raid_level == RAID::RAID5) && get_num_disks() < 3) { throw std::invalid_argument("RAID" + std::to_string((int)raid_level) +" requires at least 3 disks"); } diff --git a/src/Partition.cpp b/src/Partition.cpp index a796a27..b2f053a 100644 --- a/src/Partition.cpp +++ b/src/Partition.cpp @@ -24,6 +24,51 @@ namespace simgrid::fsmod { : name_(std::move(name)), file_system_(file_system), storage_(std::move(storage)), size_(size), free_space_(size) { } + + /** + * @brief Retrieves the partition's name + * @return a name + */ + const std::string& Partition::get_name() const { + return name_; + } + + /** + * @brief Retrieves the partition's name as a C-style string + * @return a name + */ + const char* Partition::get_cname() const { + return name_.c_str(); + } + + /** + * @brief Retrieves the partition's size in bytes + * @return a number of bytes + */ + sg_size_t Partition::get_size() const { + return size_; + } + + /** + * @brief Retrieves the partition's free space in bytes + * @return a number of bytes + */ + sg_size_t Partition::get_free_space() const { + return free_space_; + } + + /** + * @brief Retrieves the number of files stored in the partition + * @return a number of files + */ + sg_size_t Partition::get_num_files() const { + sg_size_t to_return = 0; + for (auto const &[dir_path, files] : content_) { + to_return += files.size(); + } + return to_return; + } + /** * @brief Retrieve the metadata for a file * @param dir_path: the path to the directory in which the file is located diff --git a/test/file_system_test.cpp b/test/file_system_test.cpp index 570b118..3747fb2 100644 --- a/test/file_system_test.cpp +++ b/test/file_system_test.cpp @@ -155,6 +155,9 @@ TEST_F(FileSystemTest, Directories) { XBT_INFO("Try to unlink a directory in which one file is opened. This shouldn't work"); std::shared_ptr file; ASSERT_NO_THROW(file = fs_->open("/dev/a/b/c/foo.txt", "r")); + ASSERT_EQ(file->get_path(), "/dev/a/b/c/foo.txt"); + ASSERT_EQ(file->get_access_mode(), "r"); + ASSERT_EQ(file->get_file_system(), fs_.get()); ASSERT_THROW(fs_->unlink_directory("/dev/a/b/c"), sgfs::FileIsOpenException); ASSERT_NO_THROW(file->close()); ASSERT_NO_THROW(fs_->unlink_directory("/dev/a/b/c")); diff --git a/test/one_disk_storage_test.cpp b/test/one_disk_storage_test.cpp index 26842c7..d3511d0 100644 --- a/test/one_disk_storage_test.cpp +++ b/test/one_disk_storage_test.cpp @@ -94,7 +94,7 @@ TEST_F(OneDiskStorageTest, SingleAsyncRead) { ASSERT_NO_THROW(my_read->wait()); XBT_INFO("Read complete. Clock should be at 2s"); ASSERT_DOUBLE_EQ(sg4::Engine::get_clock(), 2.0); - ASSERT_DOUBLE_EQ(file->get_num_bytes_read(my_read), 4000000); + ASSERT_DOUBLE_EQ(sgfs::File::get_num_bytes_read(my_read), 4000000); XBT_INFO("Close the file"); ASSERT_NO_THROW(file->close()); });