### Start auditd service Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Start the auditd service after installation to begin auditing system calls. ```bash sudo service auditd start ``` -------------------------------- ### Install mime-support on Ubuntu Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Install the mime-support package on Ubuntu to provide /etc/mime.types, which OSSFS uses to determine Content-Type. ```bash sudo apt-get install mime-support ``` -------------------------------- ### Install OSSFS2 on Ubuntu with dpkg Source: https://github.com/aliyun/ossfs/blob/main/README.md Install the pre-compiled OSSFS2 package on Ubuntu using dpkg. Replace .deb with the actual package file. ```bash sudo dpkg -i .deb ``` -------------------------------- ### Install ossfs2 and libfuse Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Installs the ossfs2 executable to /usr/local/bin and installs libfuse libraries to /usr/local/lib64/ossfs2/ with the name libfuse3.so.3. ```cmake install(TARGETS ossfs2 RUNTIME DESTINATION /usr/local/bin COMPONENT main) install(FILES ${LIBFUSE_LIBRARIES} DESTINATION /usr/local/lib64/ossfs2/ RENAME libfuse3.so.3 COMPONENT main) ``` -------------------------------- ### Install mailcap on CentOS Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Install the mailcap package on CentOS to provide /etc/mime.types, which OSSFS uses to determine Content-Type. ```bash sudo yum install mailcap ``` -------------------------------- ### Install OSSFS2 on Alibaba Cloud Linux/CentOS with yum Source: https://github.com/aliyun/ossfs/blob/main/README.md Install the pre-compiled OSSFS2 package on Alibaba Cloud Linux or CentOS using yum. Replace .rpm with the actual package file. ```bash sudo yum install .rpm -y ``` -------------------------------- ### Install JindoSDK shared library with execute_process Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Uses install(CODE) with execute_process and cp to install the JindoSDK shared library, following symlinks to avoid self-referencing symlink issues. Creates the target directory and copies the library to /usr/local/lib64/ossfs2/libjindosdk_c.so.6. ```cmake install(CODE " execute_process(COMMAND \${CMAKE_COMMAND} -E make_directory \"$ENV{DESTDIR}/usr/local/lib64/ossfs2\") execute_process(COMMAND cp \"${JINDOSDK_LIBRARIES}\" \"$ENV{DESTDIR}/usr/local/lib64/ossfs2/libjindosdk_c.so.6\") " COMPONENT main) ``` -------------------------------- ### Run Supervisor Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Start the Supervisor daemon to manage the ossfs process. ```bash supervisord ``` -------------------------------- ### Compile and test libfuse with Ninja Source: https://github.com/aliyun/ossfs/blob/main/dependencies/pre-built/libfuse/README.md Compile the library with Ninja, run the test suite with pytest, and install the built binaries and headers. This follows the Meson configuration step. ```bash $ ninja $ sudo python3 -m pytest test/ $ sudo ninja install ``` -------------------------------- ### Install auditd for directory scanning Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN First step to identify which process scanned your OSSFS-mounted directory: install auditd on the system. ```bash sudo apt-get install auditd ``` -------------------------------- ### Create and install mount.ossfs2 symlink Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Creates a symlink mount.ossfs2 pointing to /usr/local/bin/ossfs2 using add_custom_command and add_custom_target, then installs it to /usr/sbin. The symlink is generated as part of the ALL target. ```cmake add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/mount.ossfs2 COMMAND ${CMAKE_COMMAND} -E create_symlink /usr/local/bin/ossfs2 ${CMAKE_BINARY_DIR}/mount.ossfs2 DEPENDS ossfs2 COMMENT "Creating symlink: mount.ossfs2 -> ossfs2" ) add_custom_target(generate_ossfs2_symlink ALL DEPENDS ${CMAKE_BINARY_DIR}/mount.ossfs2) install(FILES ${CMAKE_BINARY_DIR}/mount.ossfs2 DESTINATION /usr/sbin COMPONENT main) ``` -------------------------------- ### Get uid/gid of a user with id command Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Run this command to retrieve the uid and gid of a specified user (e.g., www). The output provides numeric values needed for the uid/gid mount parameters. ```bash id www ``` -------------------------------- ### Build OSSFS2 from source with CMake Source: https://github.com/aliyun/ossfs/blob/main/README.md Compile and install OSSFS2 on Linux with GCC 9-13 and CMake 3.8+. Requires the static C++ standard library (libstdc++.a). ```bash git clone https://github.com/aliyun/ossfs.git cd ossfs mkdir build && cd build cmake .. make -j4 make install ``` -------------------------------- ### Find libfuse directory from RPM Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Locate the libfuse directory installed by the OSSFS RPM package. ```bash rpm -ql ossfs | grep fuse ``` -------------------------------- ### Install debug symbols conditionally Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Installs the ossfs2.debug file to /usr/lib/debug/usr/local/bin with component debuginfo when SEPARATE_DEBUG_SYMBOLS or CPACK_GENERATOR is set. ```cmake if (SEPARATE_DEBUG_SYMBOLS OR CPACK_GENERATOR) install(FILES ${CMAKE_BINARY_DIR}/ossfs2.debug DESTINATION /usr/lib/debug/usr/local/bin COMPONENT debuginfo) endif() ``` -------------------------------- ### Set RPATH and target properties for ossfs2 Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Configures build and install RPATHs for ossfs2 to locate libfuse and JindoSDK libraries. Sets OSSFS2_RPATH to /usr/local/lib64/ossfs2 and COMMON_RPATH to system library directories. ```cmake # we will install libfuse to /usr/local/lib64/ossfs2, make sure ossfs2 # can find it instead of using the system one set(OSSFS2_RPATH "/usr/local/lib64/ossfs2") set(COMMON_RPATH "/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64") get_filename_component(LIBFUSE_LIB_DIR ${LIBFUSE_LIBRARIES} DIRECTORY) get_filename_component(JINDOSDK_LIB_DIR ${JINDOSDK_LIBRARIES} DIRECTORY) get_filename_component(JINDOSDK_PARENT_DIR ${JINDOSDK_LIB_DIR} DIRECTORY) get_filename_component(JINDOSDK_DIR_NAME ${JINDOSDK_PARENT_DIR} NAME) set_target_properties(ossfs2 PROPERTIES BUILD_RPATH "$ORIGIN:${LIBFUSE_LIB_DIR}:${JINDOSDK_LIB_DIR}:$ORIGIN/${JINDOSDK_DIR_NAME}/lib:${OSSFS2_RPATH}:${COMMON_RPATH}" INSTALL_RPATH "$ORIGIN:${OSSFS2_RPATH}:${COMMON_RPATH}") ``` -------------------------------- ### Configure CPack DEB generator settings Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Sets Debian-specific CPack variables when CPACK_GENERATOR matches DEB, including component install, package dependencies, descriptions, and debuginfo package configuration. ```cmake if(CPACK_GENERATOR MATCHES "DEB") set(CPACK_DEB_COMPONENT_INSTALL ON) set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.17), ca-certificates") set(CPACK_DEBIAN_PACKAGE_SUMMARY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") string(CONCAT CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}" "\n" "${CPACK_PACKAGE_DESCRIPTION}") set(CPACK_DEBIAN_PACKAGE_SECTION "utils") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_GROUP}") set(CPACK_DEBIAN_MAIN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") set(CPACK_DEBIAN_MAIN_FILE_NAME "${CPACK_FILE_NAME}.deb") set(CPACK_DEBIAN_DEBUGINFO_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-dbg") set(CPACK_DEBIAN_DEBUGINFO_FILE_NAME "${CPACK_DEBUGINFO_FILE_NAME}.deb") set(CPACK_DEBIAN_DEBUGINFO_PACKAGE_DEPENDS "${CPACK_PACKAGE_NAME} (= ${CPACK_PACKAGE_VERSION})") string(CONCAT CPACK_COMPONENT_DEBUGINFO_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}" "\n" "${CPACK_PACKAGE_DEBUGINFO_DESCRIPTION}") endif() ``` -------------------------------- ### Configure CPack RPM generator settings Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Sets RPM-specific CPack variables when CPACK_GENERATOR matches RPM, including component install, package requirements, file exclusions, and debuginfo package configuration. ```cmake if(CPACK_GENERATOR MATCHES "RPM") set(CPACK_RPM_COMPONENT_INSTALL ON) set(CPACK_RPM_PACKAGE_AUTOREQ OFF) set(CPACK_RPM_PACKAGE_RELEASE "1") set(CPACK_RPM_PACKAGE_REQUIRES "glibc >= 2.17, ca-certificates") set(CPACK_RPM_PACKAGE_SUMMARY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}") set(CPACK_RPM_PACKAGE_LICENSE "Commercial") set(CPACK_RPM_PACKAGE_GROUP "${CPACK_PACKAGE_GROUP}") set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "/usr" "/usr/local" "/usr/local/bin" "/usr/local/lib64" "/usr/sbin" "/usr/lib" "/usr/lib/debug" "/usr/lib/debug/usr" "/usr/lib/debug/usr/local" "/usr/lib/debug/usr/local/bin") set(CPACK_RPM_MAIN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") set(CPACK_RPM_MAIN_FILE_NAME "${CPACK_FILE_NAME}.rpm") set(CPACK_RPM_DEBUGINFO_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-debuginfo") set(CPACK_RPM_DEBUGINFO_FILE_NAME "${CPACK_DEBUGINFO_FILE_NAME}.rpm") set(CPACK_RPM_DEBUGINFO_PACKAGE_REQUIRES "${CPACK_PACKAGE_NAME} = ${CPACK_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}") set(CPACK_COMPONENT_DEBUGINFO_DESCRIPTION "${CPACK_PACKAGE_DEBUGINFO_DESCRIPTION}") endif() ``` -------------------------------- ### Create OSSFS startup script directory Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Create the directory for the OSSFS startup script used with Supervisor. ```bash mkdir /root/ossfs_scripts ``` -------------------------------- ### Make OSSFS startup script executable Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Step 2B for CentOS7.0+: after creating /etc/init.d/ossfs from the template, grant executable permission. If the script content is correct, the bucket will be mounted when run. ```bash chmod a+x /etc/init.d/ossfs ``` -------------------------------- ### Enable OSSFS startup service with chkconfig Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Run this command to make the OSSFS startup script a service that runs automatically at startup on CentOS7.0+. ```bash chkconfig ossfs on ``` -------------------------------- ### Contents of start_ossfs.sh Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN The startup script unmounts /mnt/ossfs and runs ossfs in the foreground, which is required for Supervisor to manage it. ```bash fusermount -u /mnt/ossfs exec ossfs ... -f ``` -------------------------------- ### Mount OSS bucket using access key mount options Source: https://github.com/aliyun/ossfs/blob/main/README.md Mount the bucket by passing access key credentials directly as mount options. Replace placeholders with your actual values. ```bash ossfs2 mount /path/to/mount --oss_endpoint= --oss_bucket= \ --oss_access_key_id= --oss_access_key_secret= ``` -------------------------------- ### Write credentials to /etc/passwd-ossfs Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Step 1 of enabling automatic OSSFS mounting at startup: write the bucket name, access key ID, and secret to /etc/passwd-ossfs. The file permission must be changed to 640. ```bash echo your_bucket_name:your_access_key_id:your_access_key_secret > /etc/passwd-ossfs ``` ```bash chmod 640 /etc/passwd-ossfs ``` -------------------------------- ### Enable netfs service on CentOS6.5 Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN After configuring /etc/fstab for OSSFS auto-mount on CentOS6.5, run this command to enable the netfs service for automatic mounting at startup. ```bash chkconfig netfs on ``` -------------------------------- ### Configure libfuse build with Meson Source: https://github.com/aliyun/ossfs/blob/main/dependencies/pre-built/libfuse/README.md Extract the libfuse source archive, create a build directory, and configure the build using Meson. This is the first step in the official build procedure. ```bash $ tar xzf fuse-X.Y.Z.tar.gz; cd fuse-X.Y.Z $ mkdir build; cd build $ meson setup .. ``` -------------------------------- ### Mount OSS bucket using environment variables Source: https://github.com/aliyun/ossfs/blob/main/README.md Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables, then mount the bucket. Replace placeholders with your actual values. ```bash export OSS_ACCESS_KEY_ID= export OSS_ACCESS_KEY_SECRET= ossfs2 mount /path/to/mount --oss_endpoint= --oss_bucket= ``` -------------------------------- ### Access OSS bucket like local file system Source: https://github.com/aliyun/ossfs/blob/main/README.md After mounting, use standard shell commands to interact with the bucket as if it were a local directory. ```bash ls /path/to/mount echo "123" > /path/to/mount/test.txt cat /path/to/mount/test.txt ``` -------------------------------- ### Mount OSS bucket using ECSRAMRole Source: https://github.com/aliyun/ossfs/blob/main/README.md Mount the bucket using an ECS RAM role. Replace placeholders with your actual values. ```bash ossfs2 mount /path/to/mount --oss_endpoint= --oss_bucket= --ram_role= ``` -------------------------------- ### Add Supervisor program configuration Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Append this configuration to /etc/supervisor/supervisord.conf to define the ossfs program, including log file settings. ```ini [program:ossfs] command=bash /root/ossfs_scripts/start_ossfs.sh logfile=/var/log/ossfs.log log_stdout=true log_stderr=true logfile_maxbytes=1MB logfile_backups=10 ``` -------------------------------- ### Run OSSFS with custom LD_LIBRARY_PATH Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Run OSSFS with the correct fuse library path to avoid the version mismatch warning. ```bash LD_LIBRARY_PATH=/usr/lib ossfs... ``` -------------------------------- ### Verify Supervisor and OSSFS processes Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Check that Supervisor and OSSFS are running, then test that Supervisor restarts OSSFS after it is killed. ```bash ps aux | grep supervisor # You should be able to see the supervisor process. ps aux | grep ossfs # You should be able to see the OSSFS process. killall ossfs # Kill the OSSFS process, Supervisor is expected to restart it. ps aux | grep ossfs # You should be able to see the OSSFS process. ``` -------------------------------- ### Edit OSSFS startup script Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Open the OSSFS startup script for editing. The script unmounts /mnt/ossfs and runs ossfs in the foreground. ```bash vi /root/ossfs_scripts/start_ossfs.sh ``` -------------------------------- ### Add fstab entry for OSSFS auto-mount Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Step 2A for Ubuntu14.04 and CentOS6.5: add this line to /etc/fstab to enable automatic mounting. After saving, run 'mount -a' to verify; for CentOS6.5, also run 'chkconfig netfs on'. ```bash ossfs#your_bucket_name your_mount_point fuse _netdev,url=your_url,allow_other 0 0 ``` -------------------------------- ### Mount OSSFS with uid/gid parameters Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Use this command to make the mounted folder belong to a specific user by specifying numeric uid and gid values. Both uid and gid must be numbers. ```bash ossfs your_bucket your_mountpoint -ourl=your_url -ouid=your_uid -ogid=your_gid ``` -------------------------------- ### Check fuse library version Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Show the fuse library version from the linked path. ```bash ls -l /lib64/libfuse* ``` -------------------------------- ### Include CPack module Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Includes the CPack module to enable packaging functionality. ```cmake include(CPack) ``` -------------------------------- ### Iterate dependencies and build from source or find package Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Loops over dependencies, converts each to uppercase, and either builds from source if a source URL is set or finds the package with find_package. ```cmake FOREACH (dep ${deps}) string(TOUPPER ${dep} DEP) set(source_url "${${DEP}_SOURCE}") if (NOT source_url STREQUAL "") message(STATUS "Will build ${dep} from source") message(STATUS " URL: ${source_url}") build_from_src(dep) else () message(STATUS "Will find ${dep}") find_package(${dep} REQUIRED) endif () endforeach () ``` -------------------------------- ### Create ossfs2 executable Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Globs source files in src/ and creates an executable target ossfs2. ```cmake file(GLOB ossfs2_srcs RELATIVE "${PROJECT_SOURCE_DIR}" src/*.cpp) add_executable(ossfs2 ${ossfs2_srcs}) ``` -------------------------------- ### Patch PhotonLibOS with fault injections Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Defines custom commands to unpack and patch PhotonLibOS source. The patch file 'photon_injections.patch' is applied to the source directory, and a custom target 'photon_patched' depends on the patched output. ```cmake message("patching PhotonLibOS with fault injections") find_program(TAR_EXECUTABLE tar REQUIRED) set(PHOTON_TARBALL "${CMAKE_SOURCE_DIR}/dependencies/src/PhotonLibOS-${PHOTONLIBOS_REF}-src.tar.gz") set(PATCH_FILE "${CMAKE_SOURCE_DIR}/dependencies/patches/photon_injections.patch") set(PHOTON_PATCHED_SRC_DIR "${CMAKE_BINARY_DIR}/PhotonLibOS-patched") add_custom_command( OUTPUT ${PHOTON_PATCHED_SRC_DIR}/.unpacked COMMAND ${CMAKE_COMMAND} -E make_directory ${PHOTON_PATCHED_SRC_DIR} COMMAND tar xvf ${PHOTON_TARBALL} --strip-components=1 -C ${PHOTON_PATCHED_SRC_DIR} COMMAND ${CMAKE_COMMAND} -E touch ${PHOTON_PATCHED_SRC_DIR}/.unpacked DEPENDS ${PHOTON_TARBALL} COMMENT "Unpacking PhotonLibOS source..." ) add_custom_command( OUTPUT ${PHOTON_PATCHED_SRC_DIR}/ecosystem/oss_patched.cpp ${PHOTON_PATCHED_SRC_DIR}/.patched COMMAND patch -p1 -d ${PHOTON_PATCHED_SRC_DIR} < ${PATCH_FILE} COMMAND ${CMAKE_COMMAND} -E touch ${PHOTON_PATCHED_SRC_DIR}/.patched DEPENDS ${PHOTON_PATCHED_SRC_DIR}/.unpacked ${PATCH_FILE} COMMENT "Applying patch.diff to PhotonLibOS..." ) add_custom_target(photon_patched DEPENDS ${PHOTON_PATCHED_SRC_DIR}/.patched ) ``` -------------------------------- ### Add dependencies to ossfs2_common Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Adds libfuse, PhotonLibOS, photon_patched, and JindoSDK as dependencies, plus any actually_built dependencies. ```cmake add_dependencies(ossfs2_common libfuse PhotonLibOS photon_patched JindoSDK) if (actually_built) add_dependencies(ossfs2_common ${actually_built}) endif () ``` -------------------------------- ### Define static dependencies and create ossfs2_common library Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Sets static_deps list and creates a static library ossfs2_common from common sources, adding a patched source file and include directory. ```cmake set(static_deps ${PHOTONLIBOS_LIBRARIES} ${OPENSSL_LIBRARIES} ${GFLAGS_LIBRARIES} ${AIO_LIBRARIES} ${CITYHASH_LIBRARIES}) add_library(ossfs2_common STATIC ${ossfs2_common_srcs}) target_sources(ossfs2_common PRIVATE ${PHOTON_PATCHED_SRC_DIR}/ecosystem/oss_patched.cpp ) include_directories(${PHOTON_PATCHED_SRC_DIR}/ecosystem) ``` -------------------------------- ### Mount OSSFS with allow_other option Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Use this command to allow other users to access and mount the OSSFS-mounted folder. The allow_other parameter grants access to the mounted directory, not to files inside it; use chmod to change file permissions. ```bash ossfs your_bucket your_mount_point -ourl=your_endpoint -o allow_other ``` -------------------------------- ### Add include directories for ossfs2 Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Adds include directories for src and various dependency include directories. ```cmake include_directories( src/ ${LIBFUSE_INCLUDE_DIRS} ${PHOTONLIBOS_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS} ${CLI11_INCLUDE_DIRS} ${AIO_INCLUDE_DIRS} ${CITYHASH_INCLUDE_DIRS} ${JINDOSDK_INCLUDE_DIRS}) ``` -------------------------------- ### Check fuse version linked at runtime Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Identify the fuse library that OSSFS links to at runtime. ```bash ldd $(which ossfs) | grep fuse ``` -------------------------------- ### Build ossfs2-test executable with testing dependencies Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Defines the ossfs2-test executable when ENABLE_TESTING is set, including test source files, linking against ossfs2_common, static dependencies, and required libraries. Sets BUILD_RPATH to include runtime library directories. ```cmake if (ENABLE_TESTING) set(test_static_deps ${static_deps}) list(APPEND test_static_deps ${GOOGLETEST_LIBRARIES}) include_directories(${GOOGLETEST_INCLUDE_DIRS}) file(GLOB ossfs2_test_srcs RELATIVE "${PROJECT_SOURCE_DIR}" src/fs/test/*.cpp src/fs/test/hdfs/*.cpp src/common/test/*.cpp src/test/*.cpp) add_executable(ossfs2-test ${ossfs2_test_srcs} src/options.cpp) set_target_properties(ossfs2-test PROPERTIES BUILD_RPATH "$ORIGIN:${LIBFUSE_LIB_DIR}:${JINDOSDK_LIB_DIR}:$ORIGIN/${JINDOSDK_DIR_NAME}/lib") target_link_libraries(ossfs2-test ossfs2_common ${test_static_deps} ${LIBFUSE_LIBRARIES} rt dl pthread -static-libgcc -static-libstdc++) endif() ``` -------------------------------- ### Search audit log for directory access Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN View which processes accessed the mounted directory by searching the audit log for the directory path. ```bash ausearch -i | grep /mnt/ossfs ``` -------------------------------- ### Set dependency list and conditionally add googletest Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Defines the base dependency list (openssl, gflags, aio, cityhash) and appends googletest only when ENABLE_TESTING is true. This controls which dependencies are built. ```cmake set(deps openssl gflags aio cityhash) if (ENABLE_TESTING) list(APPEND deps googletest) endif () ``` -------------------------------- ### Link libraries for ossfs2 Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Links ossfs2 with ossfs2_common, static dependencies, libfuse libraries, and system libraries rt, dl, pthread, plus static libgcc and libstdc++. ```cmake target_link_libraries(ossfs2 ossfs2_common ${static_deps} ${LIBFUSE_LIBRARIES} rt dl pthread -static-libgcc -static-libstdc++) ``` -------------------------------- ### Set CPack common package variables Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Configures common CPack settings for the ossfs2 package, including component list, package name, version, descriptions, and file names. Sets package group to Alibaba Cloud and marks the package as non-relocatable. ```cmake set(CPACK_COMPONENTS_ALL main debuginfo) set(CPACK_PACKAGE_NAME "ossfs2") set(CPACK_DEBUGINFO_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-debuginfo") set(CPACK_PACKAGE_VERSION "${OSSFS_VERSION_ID}") set(CPACK_PACKAGE_DESCRIPTION "\ This package includes OSSFS2: A High Performance OSS Posix Client. Commit ID: ${OSSFS_COMMIT_ID}") set(CPACK_PACKAGE_DEBUGINFO_DESCRIPTION "\ This package includes debuginfo of OSSFS2. Commit ID: ${OSSFS_COMMIT_ID}") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OSSFS2: A High Performance OSS Posix Client") set(CPACK_PACKAGE_GROUP "Alibaba Cloud") set(CPACK_PACKAGE_RELOCATABLE OFF) set(CPACK_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_linux_${ARCH}") set(CPACK_DEBUGINFO_FILE_NAME "${CPACK_PACKAGE_NAME}_debuginfo_${CPACK_PACKAGE_VERSION}_linux_${ARCH}") ``` -------------------------------- ### Collect common and test source files Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Uses file(GLOB_RECURSE) to collect common and test source files, then removes test sources from common sources. ```cmake file(GLOB_RECURSE ossfs2_common_srcs RELATIVE "${PROJECT_SOURCE_DIR}" src/common/*.cpp src/fs/*.cpp src/oss/*.cpp src/metric/*.cpp src/credentials/*.cpp src/admin/*.cpp) file(GLOB_RECURSE ossfs2_test_srcs RELATIVE "${PROJECT_SOURCE_DIR}" src/common/test/*.cpp src/fs/test/*.cpp src/fs/test/hdfs/*.cpp) list(REMOVE_ITEM ossfs2_common_srcs ${ossfs2_test_srcs}) ``` -------------------------------- ### Add dependencies subdirectory and set source paths Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Adds the dependencies subdirectory and defines source tarball paths for gflags, googletest, openssl, libaio, and cityhash. These are used as CACHE STRING variables for dependency management. ```cmake add_subdirectory(dependencies) set(DEPS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/src") set(GFLAGS_SOURCE "file://${DEPS_SOURCE_DIR}/gflags-2.2.2.tar.gz" CACHE STRING "") set(GOOGLETEST_SOURCE "file://${DEPS_SOURCE_DIR}/googletest-1.12.1.tar.gz" CACHE STRING "") set(OPENSSL_SOURCE "file://${DEPS_SOURCE_DIR}/openssl-1.1.1w.tar.gz" CACHE STRING "") set(AIO_SOURCE "file://${DEPS_SOURCE_DIR}/libaio-0.3.113.tar.gz" CACHE STRING "") set(CITYHASH_SOURCE "file://${DEPS_SOURCE_DIR}/cityhash-1.1.1.tar.gz" CACHE STRING "") ``` -------------------------------- ### Unmount OSS bucket Source: https://github.com/aliyun/ossfs/blob/main/README.md Unmount the bucket when finished using the umount command. ```bash umount /path/to/mount ``` -------------------------------- ### Add post-build command to strip debug symbols Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt When SEPARATE_DEBUG_SYMBOLS or CPACK_GENERATOR is set, adds a POST_BUILD command that uses objcopy and strip to create a separate debug file and add a debuglink. ```cmake if (SEPARATE_DEBUG_SYMBOLS OR CPACK_GENERATOR) add_custom_command(TARGET ossfs2 POST_BUILD COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $ $.debug COMMAND ${CMAKE_STRIP} --strip-debug $ COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$.debug $ COMMENT "Stripping debug symbols from ossfs2 and creating separate debug file" VERBATIM) endif() ``` -------------------------------- ### CMakeLists.txt for ossfs2 build Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Main CMake configuration for ossfs2 version 2.0.10. Requires Linux, x86_64 or aarch64, and GCC >= 9. Sets C++17, debug/release flags, and options for testing, coverage, ASAN, and separate debug symbols. Retrieves commit ID and build time via git and date commands. ```cmake cmake_minimum_required(VERSION 3.8) project(ossfs2 VERSION 2.0.10) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) include(FindPackageHandleStandardArgs) include(ExternalProject) include(cmake/build-from-src.cmake) if (NOT CMAKE_SYSTEM_NAME STREQUAL Linux) message(FATAL_ERROR "Only Linux is supported") endif () # Get CPU arch execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) if (NOT (${ARCH} STREQUAL x86_64) AND NOT (${ARCH} STREQUAL aarch64)) message(FATAL_ERROR "Unknown CPU architecture ${ARCH}") endif () option(ENABLE_TESTING "Build testing" OFF) option(ENABLE_COVERAGE "Build with coverage" OFF) option(ENABLE_ASAN "Build with address sanitizer" OFF) option(SEPARATE_DEBUG_SYMBOLS "Separate debug symbols" OFF) if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9) message(FATAL_ERROR "need gcc version >= 9.0" ) endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -DNDEBUG -g") set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) # Get OSSFS2 version, commit ID and build time execute_process( COMMAND git log --format=%H -n1 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE OSSFS_COMMIT_ID OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( COMMAND date -u "+%Y-%m-%d.%H:%M:%S.%Z" OUTPUT_VARIABLE OSSFS_BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE ) set(OSSFS_VERSION_ID ${PROJECT_VERSION}) add_definitions("-D_FILE_OFFSET_BITS=64") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-error=unused-result") if (${ARCH} STREQUAL x86_64) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2 -mpclmul") endif () if (ENABLE_TESTING AND ENABLE_COVERAGE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -g") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -g") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -g") endif() if (ENABLE_ASAN) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lasan") endif () ``` -------------------------------- ### Set OpenSSL source for aarch64 in Alibaba Linux Cloud 3 Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Conditionally sets OPENSSL_SOURCE to empty when building on aarch64 in Alibaba Linux Cloud 3, forcing use of shared OpenSSL. ```cmake # We only support aarch64 in alibaba linux cloud 3, use shared openssl set(OPENSSL_SOURCE "") endif () ``` -------------------------------- ### Set default build type to Release Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Sets the default build type to RelWithDebInfo if not already specified. This ensures a release build with debug information when no build type is provided. ```cmake # Set default build type to Release if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE RelWithDebInfo) endif () ``` -------------------------------- ### Check architecture for aarch64 Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Conditional block that checks if the architecture is aarch64. The content is incomplete in the source, so only the condition is shown. ```cmake if (${ARCH} STREQUAL aarch64) ``` -------------------------------- ### Define compile definitions for ossfs2 Source: https://github.com/aliyun/ossfs/blob/main/CMakeLists.txt Adds private compile definitions OSSFS_COMMIT_ID, OSSFS_BUILD_TIME, and OSSFS_VERSION_ID to the ossfs2 target. ```cmake target_compile_definitions(ossfs2 PRIVATE OSSFS_COMMIT_ID=${OSSFS_COMMIT_ID} OSSFS_BUILD_TIME=${OSSFS_BUILD_TIME} OSSFS_VERSION_ID=${OSSFS_VERSION_ID}) ``` -------------------------------- ### Unmount OSSFS directory as non-root user Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Use this command to unmount an OSSFS-mounted directory when you are not a root user. Replace your_mountpoint with the actual mount point. ```bash fusermount -u your_mountpoint ``` -------------------------------- ### Set audit watch on mounted directory Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Configure auditd to watch the mounted directory (e.g., /mnt/ossfs) for access events. ```bash auditctl -w /mnt/ossfs ``` -------------------------------- ### Disable metadata cache Source: https://github.com/aliyun/ossfs/wiki/FAQ-EN Add this mount parameter to disable OSSFS's metadata cache, ensuring file information is always up-to-date. ```bash -omax_stat_cache_size=0 ```