Skip to content

Commit

Permalink
appFs - introduce telemetry::appFs library for managing FUSE filesyst…
Browse files Browse the repository at this point in the history
…em with telemetry librabry integration

This commit introduces the telemetry::appFs library, which seamlessly integrates with the telemetry library to simplify the management of FUSE (Filesystem in Userspace) filesystems.
  • Loading branch information
SiskaPavel committed Apr 15, 2024
1 parent ce3bba6 commit d856d7e
Show file tree
Hide file tree
Showing 5 changed files with 400 additions and 0 deletions.
71 changes: 71 additions & 0 deletions include/appFs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @file
* @brief Definition of the AppFsFuse class for managing FUSE filesystem
* @author Pavel Siska <siska@cesnet.cz>
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#pragma once

#include <fuse3/fuse.h>
#include <memory>
#include <string>
#include <telemetry.hpp>
#include <thread>

namespace telemetry::appFs {

/**
* @brief The AppFsFuse class for managing FUSE filesystem.
*/
class AppFsFuse {
public:
/**
* @brief Constructor for AppFsFuse.
*
* @param rootDirectory A shared pointer to the telemetry root directory.
*
* @throws std::runtime_error if rootDirectory is nullptr.
*/
AppFsFuse(std::shared_ptr<Directory> rootDirectory);

/**
* @brief Sets up and mounts the FUSE filesystem.
*
* This method sets up the FUSE filesystem with the provided mount point directory path.
* It creates a new thread to run the FUSE event loop.
*
* @param mountPoint The mount point directory path.
* @param tryToUnmountOnStart Whether to attempt unmounting the mount point if it's already
* mounted.
*
* @throws std::runtime_error if setup and mount process fails.
*/
void setupAndMount(const std::string& mountPoint, bool tryToUnmountOnStart = true);

/**
* @brief Unmounts the FUSE filesystem.
*
* This method unmounts the FUSE filesystem. It interrupts the FUSE event loop.
*
* @note This method is also called automatically when the AppFsFuse instance is destroyed.
*/
void unmount();

/**
* @brief Destructor for AppFsFuse.
*
* Terminates the thread running the loop.
*
* @note This method unmounts the FUSE filesystem.
*/
~AppFsFuse();

private:
std::unique_ptr<struct fuse, decltype(&fuse_destroy)> m_fuse {nullptr, &fuse_destroy};
std::shared_ptr<Directory> m_rootDirectory;
std::thread m_fuseThread;
};

} // namespace telemetry::appFs
2 changes: 2 additions & 0 deletions pkg/rpm/telemetry.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ telemetry data in your program.
%{_libdir}/libtelemetry.so
%{_includedir}/telemetry.hpp
%{_includedir}/telemetry/*.hpp
%{_libdir}/libappFs.so
%{_includedir}/appFs.hpp

%changelog
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(telemetry)
add_subdirectory(appFs)
20 changes: 20 additions & 0 deletions src/appFs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
list(APPEND APPFS_SOURCE_FILES
appFs.cpp
)

if (TELEMETRY_BUILD_SHARED)
add_library(appFs SHARED ${APPFS_SOURCE_FILES})
else()
add_library(appFs STATIC ${APPFS_SOURCE_FILES})
endif()

add_library(telemetry::appFs ALIAS appFs)

target_compile_definitions(appFs PUBLIC FUSE_USE_VERSION=30 _FILE_OFFSET_BITS=64)
target_link_libraries(appFs PUBLIC telemetry PkgConfig::fuse)
target_include_directories(appFs PUBLIC ${CMAKE_SOURCE_DIR}/include)

if (TELEMETRY_INSTALL_TARGETS)
install(TARGETS appFs LIBRARY DESTINATION ${INSTALL_DIR_LIB})
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${INSTALL_DIR_INCLUDE})
endif()
Loading

0 comments on commit d856d7e

Please sign in to comment.