set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fPIE -Wno-error=shadow -Werror=missing-field-initializers -fconcepts")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+if("${HAVE_RESIZE2FS}" STREQUAL "ON")
+ add_definitions(-DHAVE_RESIZE2FS=1)
+endif()
+
add_subdirectory(src)
add_subdirectory(tests)
+%define on_off() %{expand:%%{?with_%{1}:ON}%%{!?with_%{1}:OFF}}
+
+# resize2fs is needed for fast user add in fixed size (image) backend
+%define _with_resize2fs on
+%bcond_with resize2fs
+
Name: sessiond
Summary: Service to manage subsessions
Version: 0.10.1.1
BuildRequires: pkgconfig(libsyscommon-plugin-api-sessiond)
Requires: /usr/sbin/mkfs.ext4
+%if %{with resize2fs}
+Requires: /usr/sbin/resize2fs
+%endif
%description
%build
mkdir -p build
pushd build
-%cmake .. -DVERSION=%{version} -DCMAKE_BUILD_TYPE=Release
+%cmake .. \
+ -DVERSION=%{version} \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DHAVE_RESIZE2FS=%{on_off resize2fs}
+
make %{?jobs:-j%jobs}
popd
cp %{SOURCE1} .
}
}
+bool OS::have_resize2fs()
+{
+#ifdef HAVE_RESIZE2FS
+ return true;
+#else
+ return false;
+#endif
+}
+
+void OS::do_resize2fs(const fs::path& fs_path, uint64_t size_kB)
+{
+ // Checking this precondition is caller responsibility
+ assert(OS::have_resize2fs());
+
+ const auto child_pid = OS::throwing_fork();
+ if (child_pid == 0) {
+ const auto cmd = "/usr/sbin/resize2fs"sv;
+
+ const auto size_arg = std::to_string(size_kB);
+
+ const auto r = execl
+ ( cmd.data(), cmd.data() /* argv[0] convention */
+ , fs_path.c_str()
+ , size_arg.c_str()
+ , (char *) NULL
+ );
+
+ LOGE("Failed to execute `%s %s %s`: %m"
+ , cmd.data()
+ , fs_path.c_str()
+ , size_arg.c_str()
+ );
+ assert(r == -1);
+
+ _exit(1);
+ } else {
+ OS::throw_if_child_failed(child_pid, "resize2fs failed!");
+ }
+}
+
void OS::do_umount(const fs::path& path)
{
const auto child_pid = OS::throwing_fork();
void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB);
+ bool have_resize2fs();
+
+ void do_resize2fs(const fs::path& fs_path, uint64_t size_kB);
+
void do_mount(const fs::path& image_path, const fs::path& mount_path);
void do_umount(const fs::path& path);