Skip to content

Commit

Permalink
Code re-organization
Browse files Browse the repository at this point in the history
Documentation fixes (more to go later)
  • Loading branch information
henricasanova committed Oct 11, 2024
1 parent 68c5dff commit 014c2c9
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 67 deletions.
4 changes: 2 additions & 2 deletions conf/doxygen/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 6 additions & 13 deletions include/fsmod/File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<FileStat> stat() const;
Expand Down
2 changes: 1 addition & 1 deletion include/fsmod/FileStat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 2 additions & 10 deletions include/fsmod/FileSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileSystem>& 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> storage, sg_size_t size,
Partition::CachingScheme caching_scheme = Partition::CachingScheme::NONE);
Expand Down
7 changes: 2 additions & 5 deletions include/fsmod/JBODStorage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ namespace simgrid::fsmod {
const std::vector<simgrid::s4u::Disk*>& 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);

Expand Down
39 changes: 6 additions & 33 deletions include/fsmod/Partition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
46 changes: 46 additions & 0 deletions src/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sg_size_t>(xbt_parse_get_size("", 0, num_bytes, "")), simulate_it);
Expand All @@ -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 */
Expand Down Expand Up @@ -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_;
}


}
16 changes: 15 additions & 1 deletion src/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

}
14 changes: 13 additions & 1 deletion src/JBODStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ namespace simgrid::fsmod {
[this]() { get_message_queue()->get<void*>(); })->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");
}
Expand Down
45 changes: 45 additions & 0 deletions src/Partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/file_system_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sgfs::File> 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"));
Expand Down
2 changes: 1 addition & 1 deletion test/one_disk_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
Expand Down

0 comments on commit 014c2c9

Please sign in to comment.